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
Is your feature request related to a real problem or use-case?
I have a specific object but would like to hide the actual values to be a bit wider:
consta={foo: 'hello',bar: 45}constcurrent=a.bar// type 45// use a wider typeconstdesired=a.bar// type number
^^ i understand that using const vs let can have this happen, but I'm mostly interested in having tighter control and ensuring the wider type is always what is seen by the end user.
The intent here is to obfuscate the implementation details of certain objects because they are deemed irrelevant to the dev and subject to change at any time
Describe a solution including usage in code example
However my typescript-fu is not quite there yet and would need some help:
/** * We'd like to widen our types to not leak their implementation. * For example, when looking at types or auto-complete * a user should see: * - Sizes.Small as `string` instead of: * - Sizes.Small as `16` */// Taken from https://stackoverflow.com/questions/59355418/widen-a-type-with-a-type-generic-in-typescript// it transforms our specific types into primitive originstypeToPrimitive<T>=Textendsstring
? string
: Textendsnumber
? number
: Textendsboolean
? boolean
: T;// mapped types which will preserve keys with more wide value typestypeWiden<O>={[KinkeyofO]: ToPrimitive<O[K]>}
Who does this impact? Who is this for?
This is for anyone who would like to map an object type while using wider primitive types (me)
The text was updated successfully, but these errors were encountered:
Is your feature request related to a real problem or use-case?
I have a specific object but would like to hide the actual values to be a bit wider:
^^ i understand that using
const
vslet
can have this happen, but I'm mostly interested in having tighter control and ensuring the wider type is always what is seen by the end user.The intent here is to obfuscate the implementation details of certain objects because they are deemed irrelevant to the dev and subject to change at any time
Describe a solution including usage in code example
I have a working example based on https://stackoverflow.com/questions/59355418/widen-a-type-with-a-type-generic-in-typescript but we'd need to modify it to better handle nested objects and potentially arrays?
However my typescript-fu is not quite there yet and would need some help:
Who does this impact? Who is this for?
This is for anyone who would like to map an object type while using wider primitive types (me)
The text was updated successfully, but these errors were encountered: