Skip to content

Intl.Locale.prototype baseName & language should not be optional #47673

@swandir

Description

@swandir

lib Update Request

If I read the spec right, baseName and language properties of Intl.Locale.prototype can't be undefined, as the spec says these property accessors return a substring.

In comparison, for script it's explicitly mentioned that returned value can be undefined.

In practice, Intl.Locale constructor throws if you don't supply at least a language identifier, so it checks out.

Currently, in es2020.intl.d.ts Locale is extended from LocaleOptions that have these properties as optional.

Configuration Check

My compilation target is ES2020 and my lib is the default.

Missing / Incorrect Definition

Intl.Locale.prototype.baseName
Intl.Locale.prototype.language

Sample Code

{
  "compilerOptions": {
    "target": "ES2020",
    "strict": true
  }
}
const locale = new Intl.Locale("en");

// @ts-expect-error Intl.Locale.prototype.language currently is `string | undefined`
let language: string = locale.language;

// @ts-expect-error Intl.Locale.prototype.baseName currently is `string | undefined`
let baseName: string = locale.baseName;

Documentation Link

https://tc39.es/ecma402/#sec-Intl.Locale.prototype.baseName
https://tc39.es/ecma402/#sec-Intl.Locale.prototype.language

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions