How to change the default import hint in VSCode from ES6 to commonjs?

Viewed 923

I've a small piece of JavaScript that I open on Visual Studio Code, I then enable @ts-check to get type hinting from TypeScript definition files.

When I refer to a type that comes from a different import VSCode will give the hint and add the following code to the beginning of the file:

import { SomeType } from 'some-module';

This is correct if I'm working on ES6 but currently I'm targetting to older runtimes and would prefer to get the generated code be written using the commonjs syntax:

var SomeType = require('some-module').SomeType;

Is there any configuration I can change to achieve this behavior?

1 Answers

I'm in a similar situation. I've been able to get rid of type errors but I can't seem to figure out how to get code completion to list 'require' or 'module.exports' in its options.

To get ride of type error messages.

{ "compilerOptions": { "module": "commonjs", "target": "es2015" }, "exclude": ["node_modules"] }

Related