nativescript-community / nativescript-vscode-extension

A Visual Studio Code Extension for NativeScript
https://www.nativescript.org/visual-studio-code
Apache License 2.0
82 stars 32 forks source link

Auto importing doesn't work in VSCode #209

Open NickIliev opened 5 years ago

NickIliev commented 5 years ago

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:

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

larssn commented 5 years ago

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 :)

larssn commented 5 years ago

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.