Skip to content
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

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

Closed
4 of 5 tasks
Jack-Works opened this issue Apr 13, 2020 · 4 comments
Closed
4 of 5 tasks

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

Jack-Works opened this issue Apr 13, 2020 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@Jack-Works
Copy link
Contributor

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.
@MartinJohns
Copy link
Contributor

Duplicate of #18433.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Apr 13, 2020
@Jack-Works
Copy link
Contributor Author

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

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

Is that okay?

@Jack-Works
Copy link
Contributor Author

Be trapped by this problem just 2 minutes ago:

image

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants