Skip to content

Improve type safety of name global variable #15424

Closed
@falsandtru

Description

@falsandtru

name global variable is still assignable to string type. So name is still unsafe. name: string | undefined works better than current definition name: never.

TypeScript Version: master

Code

const n1: string = <never>name; // pass
const n2: string = <string | never>name; // pass
const n3: string = <string | undefined>name; // error, expected

Expected behavior:

declare const name: string | undefined;

Actual behavior:

declare const name: never;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions