Typescript: the tsc implementation's problem?

Created on 1 Apr 2019  ·  6Comments  ·  Source: microsoft/TypeScript

hi i got the demo code run problem when learning a crash course, and i think it might be a small problem caused by the implementation of tsc
check the follow

[root@test ts]# cat hello.ts 
const name = "world"
console.log(`hello, ${name}`)
[root@test ts]# node hello.ts 
hello, world
[root@test ts]# tsc hello.ts 
../../../.nvm/versions/node/v10.15.0/lib/node_modules/typescript/lib/lib.dom.d.ts:17846:15 - error TS2451: Cannot redeclare block-scoped variable 'name'.

17846 declare const name: never;
                    ~~~~

  hello.ts:1:7
    1 const name = "world"
            ~~~~
    'name' was also declared here.

hello.ts:1:7 - error TS2451: Cannot redeclare block-scoped variable 'name'.

1 const name = "world"
        ~~~~

  ../../../.nvm/versions/node/v10.15.0/lib/node_modules/typescript/lib/lib.dom.d.ts:17846:15
    17846 declare const name: never;
                        ~~~~
    'name' was also declared here.


Found 2 errors.


Duplicate

Most helpful comment

Name is a property of windows. Use names or _name

All 6 comments

Name is a property of windows. Use names or _name

Duplicate of #18433.

@nlwy but why the name were in the same scope in my demo files with the included libraries?

@nlwy but why the name were in the same scope in my demo files with the included libraries?

@yunfan Check the compiler options documentation: https://www.typescriptlang.org/docs/handbook/compiler-options.html

Specifically the section about --lib:

Note: If --lib is not specified a default list of libraries are injected. The default libraries injected are:
► For --target ES5: DOM,ES5,ScriptHost
► For --target ES6: DOM,ES6,DOM.Iterable,ScriptHost

In both cases DOM is included, and the DOM library contains the global name property. That is also why your error refers to the lib.dom.d.ts file.

@MartinJohns thanks for the helpful reply.

Was this page helpful?
0 / 5 - 0 ratings