|
|
|
|
|
by Jacqued
1264 days ago
|
|
You’re right about how it works today but it seems to me this is an odd choice to make. Why not enforce object types? Could they add a strictness flag that lets objects actually be type safe and enables related functions to work out of the box? For me this stuff is a regular pain point as you end up typecasting at every call site :( |
|
It would be incredibly painful to write idiomatic JS with constant narrowing required and would lead to huge performance issues.
Imagine you write some generic sort capabilities, sorting by label, createdDate, etc., and then you declare some types
Then you implement a method I've written enough, I think you can see how easily this works today and how painful and un-performant it would be to do this if you had to narrow your objects or constantly write extra info into your types to allow them to not enforce narrowing, and then there's a whole can of worms around your "widen"-able object types being illegal to functions that require exact types, ...Instead you can just write arrays...
I think TS has some issues but this isn't one of them.