Skip to content

Local variable called 'name' conflicts with lib.d.ts 'name' #31783

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

Closed
minkir014 opened this issue Jun 5, 2019 · 20 comments
Closed

Local variable called 'name' conflicts with lib.d.ts 'name' #31783

minkir014 opened this issue Jun 5, 2019 · 20 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@minkir014
Copy link

I have a variable called name and it seems to be duplicated with a const in lib.dom.d.ts and this affects some functions in vs code like hovering and going to definition.
See this picture that shows the problem of hovering

er1

and this shows the problem of going to definition when I press F12 It goes to this file

er2

@mjbvz mjbvz transferred this issue from microsoft/vscode Jun 5, 2019
@mjbvz mjbvz changed the title similar variables Local variable called 'name' conflicts with lib.d.ts 'name' Jun 5, 2019
@mjbvz
Copy link
Contributor

mjbvz commented Jun 5, 2019

If you are not targeting the web, you can disable dom typings by setting "lib": ["es6"] in your jsconfig.json:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2016",
        "jsx": "preserve",
        "lib": ["es6"]
    },
    "exclude": [
        "node_modules",
        "**/node_modules/*"
    ]
}

@mjbvz mjbvz removed their assignment Jun 5, 2019
@lll000111
Copy link

lll000111 commented Jun 6, 2019

Just for background, this is where it comes from: https://developer.mozilla.org/en-US/docs/Web/API/Window/name — meaning it's unavoidable and not a TS issue, since it is a global variable. EDIT: Okay, this should still be recognized as being overridden by a local variable in your code example. When I try that I have no issues though, "Jump to definition" takes me to the var statement and I get "var name: string" (I used a string in my test). I only get "const name: never" when I leave out the var, overriding the global "name".

@minkir014
Copy link
Author

minkir014 commented Jun 6, 2019

@mjbvz That wasn't a typescript file. It was a javascript file. I published this issue to vs code as the compiler understand that but vs code doesn't. I am targeting web for your information.

@minkir014
Copy link
Author

@lll000111 This is my code and that what I have. I don't understand how it worked for you. Tell me what's your steps.

58959598-b8207800-87a5-11e9-8ee1-3ee989861fad

@lll000111
Copy link

lll000111 commented Jun 6, 2019

Tell me what's your steps.

@minkir014

I use WebStorm — but the TS language service. If that makes any difference it's not a TS issue anyway.

I added a var name = "something"; to a random TS file I had open in a TS project (that includes "dom" lib in tsconfig.json) and a console.log(name); statement. I queried the language server with CTRL-mouseover to see the inferred type(s). I removed var and checked again (plus I got a TS error now).

@minkir014
Copy link
Author

minkir014 commented Jun 6, 2019

@lll000111 Have you hovered over the name variable in the console.log(name); statement and gave you the same result? Plus, I think that it's a vs code problem. So, I opened an issue at vs code but it was transferred here.

@minkir014
Copy link
Author

@lll000111 Are you here?

@lll000111
Copy link

@minkir014

Have you hovered over the name varia...

Yes.

Are you here?

I'm not sitting in front of a computer 24x7...

@minkir014
Copy link
Author

@lll000111 Can you transfer this issue back to vs code issues?

@lll000111
Copy link

@minkir014 Me???

@minkir014
Copy link
Author

If you can't. I'll close this issue and start another one with the same name.

@kitsonk
Copy link
Contributor

kitsonk commented Jun 7, 2019

TypeScript provides all the language services to VSCode, so it being here is appropriate.

See #18433 for further information about the issue.

@minkir014
Copy link
Author

@kitsonk Are you using vs code. If so, try that and tell me what's your solution and if not, this issue repeated many times with vs code.
#18433
#31800
Although they are in typescript repository but they are also a problem with vs code.

@mjbvz
Copy link
Contributor

mjbvz commented Jun 10, 2019

I don't know why this was closed. @minkir014 We explained why this is happening and are keeping this open to see if the experience can be improved

@minkir014
Copy link
Author

but it's strange that it works in webstorm and also the compiler understands that.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jun 13, 2019
@RyanCavanaugh
Copy link
Member

This is the intended behavior - without any other clues to the contrary, we assume you're editing a script file in a browser context.

@minkir014
Copy link
Author

My project was targeting web with HTML, CSS and JavaScript and that works perfectly in web storm and also the browser evaluates that right. So, I think it must be a problem with vs code. So, reopen this issue,please.

@minkir014
Copy link
Author

I think it's the same problem as #31800 and as what's said there the root problem is what my issue is talking about. So, reopen this issue and thank you.

@RyanCavanaugh
Copy link
Member

This is the intended behavior and we don't intend to change anything here. Issues that don't have concrete next steps are closed, so that's the state this one will remain in unless there is evidence to suggest concrete next steps that should be done from our side.

@minkir014
Copy link
Author

I am not who will tell you what will you do.. I am reporting a bug. This is not a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

5 participants