如何从文件中导入所有类型而不更改它(如test.ts下面的文件),并通过括号语法访问它们?
测试.ts
export type TEST1 = 'test1'
export type TEST2 = 'test2'
export type TEST3 = 'test3'
export type TEST4 = 'test4'
Run Code Online (Sandbox Code Playgroud)
索引.ts
import type * as T from './test'
const a: T.TEST1 = 'test1' // what i can do
type B = 'TEST2' | 'TEST3' // subset of available types in test.ts
const b: T[B] = 'test2' // what i want to do
Run Code Online (Sandbox Code Playgroud) 我搜索了一段时间,看看是否可能,我找不到任何东西,但也许我想要的是可能的,我只是用错误的搜索词进行搜索。
我想做的事
type a = 'String' | 'String/' + string;
const b: a = 'String/anything';
Run Code Online (Sandbox Code Playgroud) 我遇到的问题是,当我运行时,vsce package我仍然收到This extension consists of 3587 separate files. For performance reasons, you should bundle your extension:警告,我按照捆绑扩展步骤进行操作,调试按预期工作。
包.json
{
"main": "./out/extension",
"scripts": {
"vscode:prepublish": "webpack --mode production",
"webpack": "webpack --mode development",
"webpack-dev": "webpack --mode development --watch",
"compile": "npm run webpack",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
}
Run Code Online (Sandbox Code Playgroud)
webpack 配置是捆绑扩展示例的精确副本。