How to get intellisense for external javascript libraries with es5 and Visual Studio Code
up vote
0
down vote
favorite
I am working with project without transpilers. When I want to use external library and use intellisense in Visual Studio Code I would need to use import (which would not work with es5).
Example: I want to use axios library so I install it with npm, add script tag reference to axios.js and write the application code in app.js. I can get intellisense when I do this
import axios from 'axios';
but it would fail with es5.
I did find a hacky workaround that gives me intellisense would and not fail with es5:
var axios = axios || require('axios').default;
But at least for me this looks too hacky to me just for intellisense :)
I also noticed that for example jquery intellisense also works without import and think the reason is that jquery type definition file does not use module syntax (export) and things are added into global scope. So I am also wondering would it be somehow possible to create my own type definition file to add things into global scope?
visual-studio-code
add a comment |
up vote
0
down vote
favorite
I am working with project without transpilers. When I want to use external library and use intellisense in Visual Studio Code I would need to use import (which would not work with es5).
Example: I want to use axios library so I install it with npm, add script tag reference to axios.js and write the application code in app.js. I can get intellisense when I do this
import axios from 'axios';
but it would fail with es5.
I did find a hacky workaround that gives me intellisense would and not fail with es5:
var axios = axios || require('axios').default;
But at least for me this looks too hacky to me just for intellisense :)
I also noticed that for example jquery intellisense also works without import and think the reason is that jquery type definition file does not use module syntax (export) and things are added into global scope. So I am also wondering would it be somehow possible to create my own type definition file to add things into global scope?
visual-studio-code
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am working with project without transpilers. When I want to use external library and use intellisense in Visual Studio Code I would need to use import (which would not work with es5).
Example: I want to use axios library so I install it with npm, add script tag reference to axios.js and write the application code in app.js. I can get intellisense when I do this
import axios from 'axios';
but it would fail with es5.
I did find a hacky workaround that gives me intellisense would and not fail with es5:
var axios = axios || require('axios').default;
But at least for me this looks too hacky to me just for intellisense :)
I also noticed that for example jquery intellisense also works without import and think the reason is that jquery type definition file does not use module syntax (export) and things are added into global scope. So I am also wondering would it be somehow possible to create my own type definition file to add things into global scope?
visual-studio-code
I am working with project without transpilers. When I want to use external library and use intellisense in Visual Studio Code I would need to use import (which would not work with es5).
Example: I want to use axios library so I install it with npm, add script tag reference to axios.js and write the application code in app.js. I can get intellisense when I do this
import axios from 'axios';
but it would fail with es5.
I did find a hacky workaround that gives me intellisense would and not fail with es5:
var axios = axios || require('axios').default;
But at least for me this looks too hacky to me just for intellisense :)
I also noticed that for example jquery intellisense also works without import and think the reason is that jquery type definition file does not use module syntax (export) and things are added into global scope. So I am also wondering would it be somehow possible to create my own type definition file to add things into global scope?
visual-studio-code
visual-studio-code
edited Nov 19 at 13:32
runnerpaul
547323
547323
asked Nov 19 at 11:45
realmer
12
12
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Investigated this further and found out that indeed you can just create your own helper type definition file that will import types in module into global scope in order to use this in a ES5 project with global scope:
Create file global.d.ts (name does not matter) in your project with following contents:
import { AxiosStatic } from "axios";
declare global {
const axios: AxiosStatic;
}
That wil make intellisense work in global context (in my app.js) without having to use import. Of course only do this when you really can not use modules (global is bad :))
I'll see if I can convince vscode people (who are imho doing excellent job with this text editor :)) that this might be useful addition to the vscode documentation as well (https://github.com/Microsoft/vscode/issues/63494)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Investigated this further and found out that indeed you can just create your own helper type definition file that will import types in module into global scope in order to use this in a ES5 project with global scope:
Create file global.d.ts (name does not matter) in your project with following contents:
import { AxiosStatic } from "axios";
declare global {
const axios: AxiosStatic;
}
That wil make intellisense work in global context (in my app.js) without having to use import. Of course only do this when you really can not use modules (global is bad :))
I'll see if I can convince vscode people (who are imho doing excellent job with this text editor :)) that this might be useful addition to the vscode documentation as well (https://github.com/Microsoft/vscode/issues/63494)
add a comment |
up vote
0
down vote
Investigated this further and found out that indeed you can just create your own helper type definition file that will import types in module into global scope in order to use this in a ES5 project with global scope:
Create file global.d.ts (name does not matter) in your project with following contents:
import { AxiosStatic } from "axios";
declare global {
const axios: AxiosStatic;
}
That wil make intellisense work in global context (in my app.js) without having to use import. Of course only do this when you really can not use modules (global is bad :))
I'll see if I can convince vscode people (who are imho doing excellent job with this text editor :)) that this might be useful addition to the vscode documentation as well (https://github.com/Microsoft/vscode/issues/63494)
add a comment |
up vote
0
down vote
up vote
0
down vote
Investigated this further and found out that indeed you can just create your own helper type definition file that will import types in module into global scope in order to use this in a ES5 project with global scope:
Create file global.d.ts (name does not matter) in your project with following contents:
import { AxiosStatic } from "axios";
declare global {
const axios: AxiosStatic;
}
That wil make intellisense work in global context (in my app.js) without having to use import. Of course only do this when you really can not use modules (global is bad :))
I'll see if I can convince vscode people (who are imho doing excellent job with this text editor :)) that this might be useful addition to the vscode documentation as well (https://github.com/Microsoft/vscode/issues/63494)
Investigated this further and found out that indeed you can just create your own helper type definition file that will import types in module into global scope in order to use this in a ES5 project with global scope:
Create file global.d.ts (name does not matter) in your project with following contents:
import { AxiosStatic } from "axios";
declare global {
const axios: AxiosStatic;
}
That wil make intellisense work in global context (in my app.js) without having to use import. Of course only do this when you really can not use modules (global is bad :))
I'll see if I can convince vscode people (who are imho doing excellent job with this text editor :)) that this might be useful addition to the vscode documentation as well (https://github.com/Microsoft/vscode/issues/63494)
edited Nov 20 at 11:24
answered Nov 20 at 10:02
realmer
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373960%2fhow-to-get-intellisense-for-external-javascript-libraries-with-es5-and-visual-st%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown