Skip to content

Global declaration crashes TypeScript in Visual Studio Code #29093

@Kristonitas

Description

@Kristonitas

Premise

In my work project we are using three.js library from an external compiled source file: three.min.js. Our own codebase is being migrated to typescript, so to more easily use three.js, we try to use typings for it. Since THREE is a global namespace variable (that is defined by the library itself), we want to have it accessible in each file without any import statement. For that I am folowing this example: #3180

The problem happens if I declare THREE as a global constant. It works if I declare with a different name. The IDE doesn't show any errors and just stops compiling typescript all together.

Details

TypeScript Version: 3.2.2
Code Version: 1.30.0 (1.30.0)

Search Terms: Error processing request. Debug Failure. Expected a module symbol to be declared by a SourceFile or ModuleDeclaration.

Code

// global.d.ts
import * as _THREE from 'three';

declare global {
  const THREE: typeof _THREE;
}
// index.ts
export const a = {}; // Exporting something to make this file a module

let v = new THREE.Vector3();

Typescript Output (in IDE)

[Error  - 12:03:17] 'references' request failed with error.
Error processing request. Debug Failure. Expected a module symbol to be declared by a SourceFile or ModuleDeclaration.
Error: Debug Failure. Expected a module symbol to be declared by a SourceFile or ModuleDeclaration.
    at getReferencedSymbolsForModule (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:99136:38)
    at Object.getReferencedSymbolsForNode (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:99088:40)
    at Object.findReferencedSymbols (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:98780:60)
    at Object.findReferences (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:117557:41)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:124107:68
    at callbackProjectAndLocation (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:124160:13)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:124134:24
    at forEachProjectInProjects (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:124117:17)
    at combineProjectOutputWorker (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:124132:13)
    at combineProjectOutputForReferences (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:124090:13)
    at IOSession.Session.getReferences (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:125124:34)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:124270:61)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:125824:88
    at IOSession.Session.executeWithRequestId (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:125815:28)
    at IOSession.Session.executeCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:125824:33)
    at IOSession.Session.onMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:125846:35)
    at Interface.<anonymous> (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:127106:27)
    at emitOne (events.js:116:13)
    at Interface.emit (events.js:211:7)
    at Interface._onLine (readline.js:282:10)
    at Interface._normalWrite (readline.js:424:12)
    at Socket.ondata (readline.js:141:10)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at Pipe.onread (net.js:594:20)

Expected behavior: Show an error or work as predicted by exposing a global constant with the name THREE.

Actual behavior: Getting an error in Typescript Output tab and no syntax highlighting in my files.

Example project: https://github.com/Kristonitas/three-typings-test

package.json and tsconfig.json are included in the example project which reproduces the issue.

Related Issues: #3180

Metadata

Metadata

Assignees

Labels

CrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions