microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.65k stars 12.44k forks source link

Enable node typings if file starts with node shebang #38890

Open NightMachinery opened 4 years ago

NightMachinery commented 4 years ago

Steps to Reproduce:

Here is intellisense working correctly for a node script in a project: image

Here is another screenshot showing the support not working for a global script that does have a project:

image

As node.js is a perfectly valid choice for scripting, and has no need for verbose project structures to work, the lack of support is a bug.

System Info

CPUs | Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz (4 x 2900)
-- | --
GPU Status | 2d_canvas: enabledflash_3d: enabledflash_stage3d: enabledflash_stage3d_baseline: enabledgpu_compositing: enabledmetal: disabled_offmultiple_raster_threads: enabled_onoop_rasterization: disabled_offprotected_video_decode: unavailable_offrasterization: enabledskia_renderer: disabled_off_okvideo_decode: enabledviz_display_compositor: enabled_onviz_hit_test_surface_layer: disabled_off_okwebgl: enabledwebgl2: enabled
Load (avg) | 8, 6, 6
Memory (System) | 8.00GB (0.08GB free)
Process Argv |  
Screen Reader | no
VM | 0%

Extension | Author (truncated) | Version
-- | -- | --
better-comments | aar | 2.0.5
interactive-scala | als | 1.2.1
better-toml | bun | 0.3.2
gitignore | cod | 0.6.0
bracket-pair-colorizer-2 | Coe | 0.1.3
scala | dal | 0.0.5
vsc-material-theme | Equ | 32.6.0
vsc-material-theme-icons | equ | 1.1.4
language-julia | jul | 0.15.32
crystal-ide | kof | 0.0.4
dotty | lam | 0.1.16
Lisp | mat | 0.1.10
vscode-docker | ms- | 1.2.0
python | ms- | 2020.5.78807
remote-containers | ms- | 0.117.1
remote-ssh | ms- | 0.51.0
remote-ssh-edit | ms- | 0.51.0
remote-wsl | ms- | 0.44.2
vscode-remote-extensionpack | ms- | 0.20.0
powershell | ms- | 2020.4.0
vscode-paste-image | mus | 1.0.4
gradle-language | nac | 0.2.3
java | red | 0.61.0
datetime | rid | 2.0.1
rust | rus | 0.7.8
scala | sca | 0.3.9
ayu | tea | 0.18.0
vscode-lldb | vad | 1.5.0
vscodeintellicode | Vis | 1.2.7
vscode-java-debug | vsc | 0.26.0
vscode-java-dependency | vsc | 0.10.1
vscode-java-pack | vsc | 0.9.1
vscode-java-test | vsc | 0.22.4
vscode-maven | vsc | 0.21.4
org-mode | vsc | 1.0.0
vim | vsc | 1.14.4
debug | web | 0.24.0
markdown-all-in-one | yzh | 2.8.0
vscodebot[bot] commented 4 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

mjbvz commented 4 years ago

What does project mean here? Are you using a jsconfig.json project? Just opening a folder?

Can you please share example code (as text) or an example project along with more detailed steps to reproduce the issue

NightMachinery commented 4 years ago

@mjbvz Here are my current project-less JavaScript scripts. I mean that they are traditional unix shebang scripts, with no extra config file whatsoever. They simply use the global environment, just as a simple python script might do (as opposed to a python package).

mjbvz commented 4 years ago

Similar to https://github.com/microsoft/TypeScript/issues/30902

The issue seems to be that we aren't picking up any signals that these JS files should have node apis enable

As a workaround, you can either npm install @types/node into your workspace or create a jsconfig that explicitly includes the node typings:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2016",
        "jsx": "preserve",
    },
    "exclude": [
        "node_modules",
        "**/node_modules/*"
    ],
    "typeAcquisition": {
        "include": [
            "node"
        ]
    }
}
NightMachinery commented 4 years ago

@mjbvz I added that jsconfig file, and now node API is recognized by the IntelliSense, but required packages are not. Is there a way to solve that?

photo_2020-06-02_15-36-43