Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set global declaration in vscode JavaScript

I'm working on a JavaScript transpiler that apart from other things will also replace certain functions and variables upon build.

For example the following file (./src/my-module.js):

defineModule("MyModule", function(exports) {
  return exports;
});

Will be copied and converted to (./build/my-module.js):

(function(global, factory) {
  "use strict";
  if (typeof exports !== "undefined" && typeof module !== "undefined") module.exports.MyModule = factory(exports.MyModule || {});
  else factory(global.MyModule = {});
})(this, function(exports) {
  return exports;
});

Some of these functions could also return a result. In that case I would like to be able to declare the types of the parameters and the result of the function without using require. Is it possible to have a global .d.ts definition in VSCode?

So far, all I've done is add the functions to the global variable of eslint so as to not have errors.

like image 903
nick zoum Avatar asked Jul 03 '19 09:07

nick zoum


1 Answers

You can specify your own TypeScript folder path in your settings.json where you can specify your own lib.*.d.ts files using the typescript.tsdk option.

{
  "typescript.tsdk": "node_modules/typescript/lib"
}
like image 77
mootrichard Avatar answered Oct 26 '22 06:10

mootrichard