-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intl types: Better typing for exactOptionalPropertyTypes needed #45652
Comments
I'm half-half on this, |
My real world code is something like that: let timeZone: string | undefined = getUserTimeZone();
let IntlOptions: Intl.DateTimeFormatOptions = {
timeZone: timeZone
}; refactoring to let timeZone: string | undefined = getUserTimeZone();
let IntlOptions: Intl.DateTimeFormatOptions = {};
if (timeZone) {
IntlOptions.timeZone = timeZone;
} to make TS happy feels clumsy. |
Yeah, that seems reasonable to me |
…ptionalPropertyTypes - see microsoft#45652
I would love if the setting of undefined would simply delete the key in the object...i.e. set it to the default of |
Seems like you just want |
Is it? I was under the impression that 2 != 3? (But it is more about category then arithmetics) when:
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 |
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 |
// exactOptionalPropertyTypes: true
foo.optional = undefined; // error
delete foo.optional; // all good |
* Import of Intl.Locale from #39664 * Handle updating es2020.intl and add es2021 for new DateTimeFormatOptions options - re: #39664 * Extends DateTimeFormatOptions for new Intl APIs - re: #45420 * Handle migrating Intl.NumberFormat.formatToParts to es2018 (keeping esnext.intl around) * Adds Intl.DisplayNames to es2020 - re: #44022 * Remove attributes added in es2021 from es2020 - re: #42944 * Add a reference to es2021 in the command line parser * Adds some docs about the lib files * Baselines * Allow undefined in Intl inputs to allow for ergonomic usage of exactOptionalPropertyTypes - see #45652 * Adds some tests covering the APIs * Apply suggestions from code review Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> * Handle PR feedback * More review improvements Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This is included with #45647 👍🏻 |
Bug Report
I did not find a "planning" issue for related issues.
All delivered types should be safe to use with the new Typescript option.
🕗 Version & Regression Information
⏯ Playground Link
Workbench Repro
🙁 Actual behavior
Type 'undefined' is not assignable to type 'string'.(2322)
🙂 Expected behavior
Should compile because undefined is a valid property for that object.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat
copied from microsoft/TypeScript-DOM-lib-generator#1126
The text was updated successfully, but these errors were encountered: