ignoring custom typescript dts type definition files for javascript modules
See original GitHub issueTS Template added by @mjbvz
TypeScript Version: 3.9.7
Search Terms
- javascript, js
- d.ts
Issue Type: Bug
- Clone my example repository.
- Add the repository folder to a VS Code workspace.
- In a terminal, go to the repository folder and run
npm install
npm run test_with_types
- The project should build and run some Mocha tests successfully.
- In VS Code, open the
test/legacy.test.ts
file.
Expected result
VS Code should not report any errors in test/legacy.test.ts
.
Actual result
VS Code applies an error annotation where the file references the legacy.FooOptions
type: Namespace '"/<path_omitted>/typescript_custom_dts_issue/src/legacy"' has no exported member 'FooOptions'.ts(2694)
.
The FooOptions
type is declared in the src/legacy.d.ts
custom type definition file. The NPM script build:copy_types
copies that custom type declaration file to the lib
directory, which is the outDir
configured in src/tsconfig.json
. VS Code appears to ignore that type definition file. Note that importing the legacy
module in the test file using ../src/legacy
removes the error annotation, but the test generates a runtime error that the module ../src/legacy
cannot be found because of course Node cannot load a .ts
TypeScript module.
I thought perhaps source maps might be causing VS Code to ignore the definition file in the lib
directory, but deleting the source maps and reloading the project did not resolve the issue. Could this have something to do with VS Code attempting to account for the project reference from test/tsconfig.json
to src/tsconfig.json
?
I have also used the Insider version of VS Code to test and reproduce this issue.
VS Code version: Code 1.47.2 (17299e413d5590b14ab0340ea477cdd86ff13daf, 2020-07-15T18:18:50.054Z) OS version: Darwin x64 19.5.0
System Info
Item | Value |
---|---|
CPUs | Intel® Core™ i9-9880H CPU @ 2.30GHz (16 x 2300) |
GPU Status | 2d_canvas: enabled flash_3d: enabled flash_stage3d: enabled flash_stage3d_baseline: enabled gpu_compositing: enabled metal: disabled_off multiple_raster_threads: enabled_on oop_rasterization: disabled_off protected_video_decode: unavailable_off rasterization: enabled skia_renderer: disabled_off_ok video_decode: enabled viz_display_compositor: enabled_on viz_hit_test_surface_layer: disabled_off_ok webgl: enabled webgl2: enabled |
Load (avg) | 2, 2, 2 |
Memory (System) | 32.00GB (0.22GB free) |
Process Argv | |
Screen Reader | no |
VM | 0% |
Extensions (47)
Extension | Author (truncated) | Version |
---|---|---|
vscode-openapi | 42C | 3.4.0 |
al-code-outline | and | 2.0.4 |
asciidoctor-vscode | asc | 2.8.3 |
better-toml | bun | 0.3.2 |
solargraph | cas | 0.21.1 |
npm-intellisense | chr | 1.3.0 |
path-intellisense | chr | 2.2.1 |
vscode-eslint | dba | 2.1.8 |
javascript-ejs-support | Dig | 1.3.1 |
docs-yaml | doc | 0.2.5 |
xml | Dot | 2.5.0 |
gitlens | eam | 10.2.2 |
vscode-html-css | ecm | 0.2.3 |
vscode-npm-script | eg2 | 0.3.12 |
go | gol | 0.15.1 |
gc-excelviewer | Gra | 3.0.38 |
vscode-nginx-conf-hint | han | 0.1.0 |
vscode-test-explorer | hbe | 2.19.1 |
rest-client | hum | 0.24.1 |
search-node-modules | jas | 1.3.0 |
asciidoctor-vscode | joa | 2.8.0 |
svg | joc | 1.3.5 |
sublime-babel-vscode | jos | 0.2.10 |
vscode-colorize | kam | 0.8.17 |
node-module-intellisense | lei | 1.5.0 |
Kotlin | mat | 1.7.1 |
rainbow-csv | mec | 1.7.0 |
vscode-docker | ms- | 1.3.1 |
python | ms- | 2020.7.94776 |
cpptools | ms- | 0.29.0 |
debugger-for-chrome | msj | 4.12.9 |
gradle-language | nac | 0.2.3 |
node-modules-resolve | nau | 1.0.2 |
vscode-gitignore-generator | pio | 1.0.2 |
vscode-manifest-yaml | Piv | 1.19.0 |
polymer-ide | pol | 0.6.0 |
qub-xml-vscode | qub | 1.2.8 |
vscode-yaml | red | 0.9.1 |
sass-indented | rob | 1.5.1 |
rewrap | stk | 1.12.0 |
code-spell-checker | str | 1.9.0 |
json2yaml | tux | 0.2.0 |
vscode-sourcemaps-navigator | vlk | 0.0.3 |
nodejs-extension-pack | wad | 0.1.9 |
crs-al-language-extension | wal | 1.2.4 |
JavaScriptSnippets | xab | 1.8.0 |
openapi-preview | zoe | 1.7.1 |
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
This sounds like a configuration error, not a bug. We can investigate if this is reduced to just a set of files that clearly demonstrates a defect
Thanks for your response @DanielRosenwasser.
Your description of the symptoms seems correct on the surface, though I reiterate that the project builds from the command line with
tsc
, while VS Code reports errors in thetest
files that importsrc
modules with corresponding.d.ts
files. VS Code does not see the “intended” types, so marks the code with errors, and intellisense does not work.If you examine the project in the linked repository, you’ll see that the build script does what you say and injects the
.d.ts
files that type the JavaScript modules from thesrc
directory into thelib
directory. The problem is VS Code does not see thelib
.d.ts
files that thetest
files import. When I ctrl-click on one of those imported modules from atest
file, VS Code jumps to the JavaScript file in thesrc
directory, which might provide some clue as to the cause.Additionally, you’ll see from my comments in the linked related issue that the workaround of copying
.d.ts
files fromsrc
tolib
necessitates explicitly compilingsrc
, then copying the.d.ts
files tolib
, then compilingtest
, which completely defeats the purpose of using the project reference fromtest
tosrc
. Therefore, I believe part of the solution involves the TypeScript compiler emitting custom DTS files by default rather than generating its own.