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
I'm creating this issue to suggest a feature which is kind of related with type reflection. I don't know if it is possible to implement or if it is something that aligns with the TypeScript project goals but I though that it would be worth to share it...
The problem
I'm trying to think about ways to improve the support for immutable.js or similar libraries.
The current .d.ts file uses a generics and two type arguments (key and value) to declare aMap:
Hi,
I'm creating this issue to suggest a feature which is kind of related with type reflection. I don't know if it is possible to implement or if it is something that aligns with the TypeScript project goals but I though that it would be worth to share it...
The problem
I'm trying to think about ways to improve the support for immutable.js or similar libraries.
The current
.d.ts
file uses a generics and two type arguments (key and value) to declare aMap
:This is a problem because in some cases not all the values will be of the same type:
However, this is not a major problem because we can use union types:
The second problem is more serious:
The compiler is not able to validate that we have used the correct string literal.
The not so good solution
After trying a few things I decided I decided that it would be much better to do something like the following:
The main problem I see with this is having to manually create the following type:
I believe that this is a potential failure point. A place in which we may type something incorrectly or forget one of the properties.
The suggested solution
I was wondering if it would be possible to implement a design time only type operator. I have called this operator
propertiesOf
:If this operator was applicable to generic types we could re-implement the immutable example as follows:
I'm not sure but this operator could maybe also prevent index property access errors?
Thanks in advance for taking the time to review this 👍
The text was updated successfully, but these errors were encountered: