Auto importing doesn't work in VSCode
From @larssn on September 19, 2018 8:8
Tell us about the problem
So our company just switched to NativeScript from Cordova, and we're used to VSCode being able to auto-import classes etc. that reside in node_modules. However that doesn't seem to work for NativeScript, where it works for everything else.
Which platform(s) does your issue occur on?
Mac/Windows
Please provide the following version numbers that your issue occurs with:
- CLI: 4.2.3
- Cross-platform modules: 4.2.0
- Runtime(s): 4.2.0 & 4.2.0
- Plugin(s): "nativescript-angular": "^6.1.0", "nativescript-plugin-firebase": "^6.8.1", "nativescript-theme-core": "~1.0.4", "nativescript-ui-listview": "^3.6.1", "nativescript-ui-sidedrawer": "~4.2.0",
Please tell us how to recreate the issue in as much detail as possible.
Just create a new NS angular project. Go into app.component.ts and paste the following constructor.
constructor(
private modalService: ModalDialogService
) { }
Confirm that VSCode can't figure out where ModalDialogService is located ('No suggestions' dialog).
Now confirm that you have the module already, by pasting the import import { ModalDialogService } from 'nativescript-angular/directives/dialogs';
Auto imports is a really important feature to us, being new at the framework in general. It greatly speeds up our workflow.
Copied from original issue: NativeScript/NativeScript#6279
I should add that I'm already using the NativeScript extension in VSCode (if that is required), and no auto-imports.
And sorry for posting in the wrong issue tracker :)
So creating a references.d.ts file with the contents: /// <reference path="node_modules/tns-core-modules/tns-core-modules.d.ts" /> fixes the problem.
Any reason creating a new plugin doesn't ship with this?
Also, have you considered using the @types functionality that TS2.0 introduced? I'm talking about something like npm install @types/tns-core-modules --save-dev.