如果我输入以下内容:
interface A {
x: number
}
interface B {
y: number
}
type Z = A | B;
// here it allows me to create a variable of type Z with both members of type A and B.
let z: Z = {
x: 5,
y: 6,
}
Run Code Online (Sandbox Code Playgroud)
我无法确保 Z 类型的对象确实包含 A 的所有成员但不包含 B 的成员(或相反)。使用 TypeScript 有可能吗?经过大量研究,我倾向于“不”的答案,但我不确定。
在编写稍后将通过 webpack 推送的代码时,可以对非标准文件使用自定义加载器。实际上可以写
import image from './assets/image.png';
Run Code Online (Sandbox Code Playgroud)
并且会妥善处理。问题是VSCode并不像文件提供自动完成.png,.svg,.scss等等。
是否可以通过某些设置或扩展来做到这一点?
javascript ide intellisense visual-studio-code vscode-settings