如何让 VSCode/Typescript 在导入的 类 上自动完成?
How to let VSCode/Typescript to do auto complete on imported classes?
假设我有一个文件,class.ts
//I tried implementing interface, but it won't help, with or without the interface
interface FooInterface {
bar: Function
}
class Foo implements FooInterface {
bar() {
console.log('Hello world!');
}
}
export = new Foo();
在我的其他文件 index.js
中,我希望 VS Code 能够读取 class Foo
中的内容并自动完成,但事实并非如此。
const Foo = require('./class');
///Expecting the .bar() suggestion after typing Foo., but it didn't happen
Foo.bar();
我错过了什么吗?我应该怎么做才能让 VS Code 识别出 class 中可用的 methods/properties?许多第三方库都可以做到这一点。
我觉得这个模式有点奇怪,所以我为你创建了一个沙箱,
希望对您有所帮助
这里是沙箱:https://codesandbox.io/s/vigorous-fog-hngl5?file=/src/index.js:0-72
如果您想查看差异,我也会将代码粘贴到此处
interface FooInterface {
bar: () => void
}
export default class Foo implements FooInterface {
bar() {
console.log('Hello world!');
}
}
这是导入它的方法:
import Foo from './class';
const FooInstance = new Foo();
这是结果:
假设我有一个文件,class.ts
//I tried implementing interface, but it won't help, with or without the interface
interface FooInterface {
bar: Function
}
class Foo implements FooInterface {
bar() {
console.log('Hello world!');
}
}
export = new Foo();
在我的其他文件 index.js
中,我希望 VS Code 能够读取 class Foo
中的内容并自动完成,但事实并非如此。
const Foo = require('./class');
///Expecting the .bar() suggestion after typing Foo., but it didn't happen
Foo.bar();
我错过了什么吗?我应该怎么做才能让 VS Code 识别出 class 中可用的 methods/properties?许多第三方库都可以做到这一点。
我觉得这个模式有点奇怪,所以我为你创建了一个沙箱,
希望对您有所帮助
这里是沙箱:https://codesandbox.io/s/vigorous-fog-hngl5?file=/src/index.js:0-72
如果您想查看差异,我也会将代码粘贴到此处
interface FooInterface {
bar: () => void
}
export default class Foo implements FooInterface {
bar() {
console.log('Hello world!');
}
}
这是导入它的方法:
import Foo from './class';
const FooInstance = new Foo();
这是结果: