You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thank you for reporting this, and sorry for late response.
This is actually an “improvement” compared to the original result; see the below example.
better-typescript-lib considers the possibility of existence of properties that do not appear in types.
Actually TypeScript's lib does the same thing for Object.keys (which always returns string[]), but somehow doesn't for Object.entries and Object.values.
Ideally we should have detected an object literal directly passed to Object.entries so that such a consideration isn't needed, but I think this isn't possible with current type system.
typeFooObj={foo: number;}constobj1={foo: 123,bar: "Hello!"}constobj2: FooObj=obj1;for(const[key,value]ofObject.entries(obj2)){// Default TypeScript definition: value is number// better-typescript-lib: value is unknownconsole.log(value);// 123 and "hello!" are shown}
In the typescript lib, the union type of values simply becomes the new value type.
Compared to the above, the implementation of this lib is a bit more complex.
Please let me know if I've missed something.
The text was updated successfully, but these errors were encountered: