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
{{ message }}
Repository navigation
Intl types: Better typing for exactOptionalPropertyTypes needed #45652
I'm half-half on this, undefined is the default for those values, yes, but it's not documented as something you should really pass in via that MDN page - can you think of a specific reason why we should add this?
to make TS happy feels clumsy.
My API returns "use client setting" explicit as undefined (for timezone and locale) to allow direct use in the modern browser APIs.
I would love if the setting of undefined would simply delete the key in the object...i.e. set it to the default of timeZone?
Seems like you just want exactOptionalPropertyTypes: false then.
Is it? I was under the impression that 2 != 3? (But it is more about category then arithmetics)
when: exactOptionalPropertyTypes: false
timeZone can be not set
timeZone: can be string
timeZone can be undefined
exactOptionalPropertyTypes: true
timeZone can be not set, but you can not get here back by yourself.
timeZone: can be string 3) timeZone can be undefined
I am asking for a 3rd way: where you can unset the value or it holds value of specific type... so we can still use the ? optional bit on the type but in this stricter way...
We might need some other annotation like it can not be unset maybe a +?
Maybe I'm also confused, but point is seems to be what this issue is about. The change would allow all three options by adding | undefined in the .d.ts which you can see in orta@689bf6f
Activity
orta commentedon Aug 31, 2021
I'm half-half on this,
undefinedis the default for those values, yes, but it's not documented as something you should really pass in via that MDN page - can you think of a specific reason why we should add this?HolgerJeromin commentedon Aug 31, 2021
My real world code is something like that:
refactoring to
to make TS happy feels clumsy.
My API returns "use client setting" explicit as
undefined(for timezone and locale) to allow direct use in the modern browser APIs.orta commentedon Aug 31, 2021
Yeah, that seems reasonable to me
Allow undefined in Intl inputs to allow for ergonomic usage of exactO…
tolysz commentedon Aug 31, 2021
I would love if the setting of undefined would simply delete the key in the object...i.e. set it to the default of
timeZone?nmain commentedon Aug 31, 2021
Seems like you just want
exactOptionalPropertyTypes: falsethen.tolysz commentedon Sep 1, 2021
Is it? I was under the impression that 2 != 3? (But it is more about category then arithmetics)
when:
exactOptionalPropertyTypes: falsetimeZonecan be not settimeZone: can bestringtimeZonecan be undefinedexactOptionalPropertyTypes: truetimeZonecan be not set, but you can not get here back by yourself.timeZone: can bestring3)timeZonecan be undefinedI am asking for a 3rd way: where you can unset the value or it holds value of specific type... so we can still use the
?optional bit on the type but in this stricter way...We might need some other annotation like it can not be unset maybe a
+?orta commentedon Sep 1, 2021
Maybe I'm also confused, but point is seems to be what this issue is about. The change would allow all three options by adding
| undefinedin the.d.tswhich you can see in orta@689bf6ffatcerberus commentedon Sep 2, 2021
Marcin Tolysz (@tolysz)
Intl 2021 Updates (#45647)
orta commentedon Sep 8, 2021
This is included with #45647 👍🏻