0

I downloaded the most recent version of TypeScript and NodeJS, obtained a small example in TypeScript, and attempted to compile using both Node terminal and a Windows 10 command line. Please see below:

The sample program I'm using is:

let greeting:string = "Hello!";
console.log(greeting);
C:\Users\CaitlinG>tsc greet.ts
node_modules/@types/mongodb/index.d.ts:482:22 - error TS2304: Cannot find name 'PromiseConstructor'.

482     promiseLibrary?: PromiseConstructor;
                         ~~~~~~~~~~~~~~~~~~

node_modules/@types/mongoose/index.d.ts:1706:26 - error TS2507: Type 'MapConstructor' is not a constructor function type.

1706     class Map<V> extends global.Map<string, V> {
                              ~~~~~~~~~~

node_modules/@types/mongoose/index.d.ts:1716:37 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `l
ib` compiler option to es2015 or later.

1716   interface GlobalMap<K, V> extends Map<K, V> {}
                                         ~~~

node_modules/@types/webgl2/index.d.ts:582:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'WebGL2RenderingConte
xt' must be of type '{ new (): WebGL2RenderingContext; prototype: WebGL2RenderingContext; readonly ACTIVE_ATTRIBUTES: number; readonly ACTIVE_TEXTURE:
 number; ... 556 more ...; readonly WAIT_FAILED: number; }', but here has type '{ new (): WebGL2RenderingContext; prototype: WebGL2RenderingContext; r
eadonly ACTIVE_ATTRIBUTES: number; readonly ACTIVE_TEXTURE: number; ... 557 more ...; readonly MAX_CLIENT_WAIT_TIMEOUT_WEBGL: number; }'.

582 declare var WebGL2RenderingContext: {
                ~~~~~~~~~~~~~~~~~~~~~~

  AppData/Roaming/npm/node_modules/typescript/lib/lib.dom.d.ts:16316:13
    16316 declare var WebGL2RenderingContext: {
                      ~~~~~~~~~~~~~~~~~~~~~~
    'WebGL2RenderingContext' was also declared here.

I don't understand how to resolve these issues.

8
  • Either you are not showing us all of greet.ts or something is very wrong with your system. Commented Jun 3, 2020 at 18:37
  • 1
    Share your tsconfig. Commented Jun 3, 2020 at 18:37
  • 1
    Create a new folder in the root of a drive. Create a new text file in that folder. Copy just those two lines into that text file. Rename the text file greet.ts. Open the Windows Command Line. Navigate to the new folder you created. Type tsc greet.ts and press Enter. If you still get those same errors, then we'll have something to discuss. Commented Jun 3, 2020 at 18:42
  • 1
    I'm guessing your tsconfig is missing the appropriate compilerOptions.target and compilerOptions.lib settings. Commented Jun 3, 2020 at 18:43
  • A quick drop of your code in a codesandbox environment shows it's working as expected. I suspect a configuration issue, as the stack trace is complaining about a constructor from @types/mongodb, which isn't referenced from your source (at least not directly). Commented Jun 3, 2020 at 18:44

1 Answer 1

1

Try adding the following in your tsconfig.

"compilerOptions": {
    "lib": ["dom", "es6"]
}
Sign up to request clarification or add additional context in comments.

10 Comments

The errors were still there, but the js file was created. This seems very strange. I'm using the newest version of Node, 14.4.0. Could this pose a problem?
Did u tried exiting from the node terminal and re-running it again ?
Inside vscode or running node on the command line, then running the typescript program at the node prompt, '>'?
exit from all the terminal , open only one either command line or vs code's terminal, and run the command again
OK. I did that. The errors are still there. I ran: tsc greet.ts on the command line (not in vscode). I added "compilerOptions": { "lib": ["dom", "es6"] }
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.