我正在尝试找出一种在TypeScript中让TSDocs处理字符串文字类型声明的方法。
例如:
type InputType =
/** the TSDoc doesn't works for num1, but i'd like it to */
'num1' |
/** the TSDoc doesn't work for num2, but i'd also like it to */
'num2'
export const test = (...input: InputType[]) => {
return input
}
tac('num1')我希望'num1' & 'num2在VSCode或其他工具中显示带有注释的TSDoc,但这些工具当前在键入'ma1'时不显示注释。
有没有办法做到这一点?
发布于 2021-04-24 22:46:26
这是你可以做的另一个选择:
type InputType = "num1" | "num2";
/**
*
* @param {"num1"} input description for num2
*/
function test(...input: ["num2", ...string[]]): ["num2"];
/**
*
* @param {"num1"} input description for num1
*/
function test(...input: ["num1", ...string[]]): ["num1"];
/**
*
* @param {string} input description for numX
*/
function test(...input: [string, ...string[]]): ["numX"];
function test<T extends InputType, R extends T[]>(...input: [...R]) {
return input;
}
test("num4");

发布于 2021-04-23 23:38:45
你想要这样的东西是正确的吗:
/**
* the TSDoc works for num1
*/
type A = 'num1';
/**
* the TSDoc works for num2
*/
type B = 'num2';
export const test = (...input: (A | B)[]) => {
return input
}
test('num1');https://stackoverflow.com/questions/56748729
复制相似问题