typescript - 如何让 VSCode/Typescript 对导入的类进行自动完成?
问题描述
假设我有一个文件,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 能够读取类中的内容Foo
并自动完成,但事实并非如此。
const Foo = require('./class');
///Expecting the .bar() suggestion after typing Foo., but it didn't happen
Foo.bar();
我错过了什么吗?我应该怎么做才能让 VS Code 识别类中可用的方法/属性?许多第三方库都能够做到这一点。
解决方案
这个模式对我来说有点奇怪,所以我为你创建了一个沙箱,
希望它会有所帮助
这是沙箱: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();
推荐阅读
- postgresql - 由于计划时间小于执行时间,如何减少查询的执行时间?
- postgresql - 如何计算Postgresql中的结果数量忽略一对多连接
- java - Primefaces:操作(-Listener)完成后更新
- c# - 如何使默认 TreeView (System.Windows.Controls) 具有与 RadTreeView (telerik) 相同的样式?
- tensorflow - 使用 ssd_inception_v2 训练不同的分辨率
- hdfs - 使用 Impala 在 HDFS 中查询 Parquet 文件
- python - 如何检查日期是否在周范围内?
- git - 撤消导致我正在合并的分支上的工作丢失的合并提交
- python - 关于为什么这两种方法有不同结果的 Python 不可散列类型 dict 问题
- c - 如何检查字符串匹配格式“printf like - %d/...”