小编Syl*_*ler的帖子

获取命名空间的键并使用括号访问命名空间成员

如何从文件中导入所有类型而不更改它(如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)

typescript typescript-typings

8
推荐指数
1
解决办法
499
查看次数

是否可以将部分通配符分配给打字稿中的类型?

我搜索了一段时间,看看是否可能,我找不到任何东西,但也许我想要的是可能的,我只是用错误的搜索词进行搜索。

我想做的事

type a = 'String' | 'String/' + string;
const b: a = 'String/anything';
Run Code Online (Sandbox Code Playgroud)

typescript

3
推荐指数
1
解决办法
1829
查看次数

如何使用 webpack 正确捆绑 vscode 扩展

我遇到的问题是,当我运行时,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 配置是捆绑扩展示例的精确副本。

visual-studio-code vscode-extensions

3
推荐指数
1
解决办法
4322
查看次数