Skip to content

Feature request: special handling on "name" in libdom.d.ts #37930

@Jack-Works

Description

@Jack-Works

Search Terms

libdom name

Suggestion

When checking the identifier definition, if the symbol is defined in libdom.d.ts and the identifier is called name, emit a diagnostics.

Use Cases

name is a common variable in daily programming, unfortunately, there is a global variable named name in libdom.d.ts ( https://developer.mozilla.org/en-US/docs/Web/API/Window/name )

Now the global name is type never but not all cases are covered by the never type. for example:

export function x(y: string) {
    if (y === name) return true
    //        ~~~~ implicit bug, typescript won't give a type error here
    return false
}

This is a breaking change. And if someone really wants to use the global name, I'd like to suggest them to use window.name.

I'd like to implement this feature if the TypeScript team will accept it.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions