improved literal handling on type declaration

This commit is contained in:
WolverinDEV 2019-04-04 18:15:28 +02:00
parent 41c45a0c8a
commit efb4bad182
3 changed files with 27 additions and 13 deletions

View file

@ -371,7 +371,24 @@ generators[SyntaxKind.VariableStatement] = (settings, stack, node: ts.VariableSt
}; };
generators[SyntaxKind.TypeAliasDeclaration] = (settings, stack, node: ts.TypeAliasDeclaration) => { generators[SyntaxKind.TypeAliasDeclaration] = (settings, stack, node: ts.TypeAliasDeclaration) => {
return node; let type = node.type;
if(type.kind == SyntaxKind.UnionType) {
const union_members = [];
const union = <ts.UnionTypeNode>node.type;
for(const element of union.types as any as any[]) {
if(element.kind === SyntaxKind.LiteralType && element.literal && element.literal.text) {
union_members.push(ts.createStringLiteral(element.literal.text));
}
else
union_members.push(element);
console.log(SyntaxKind[element.kind]);
}
type = ts.createUnionTypeNode(union_members);
}
return ts.createTypeAliasDeclaration(node.decorators, node.modifiers, node.name, node.typeParameters, type);
}; };
generators[SyntaxKind.EnumMember] = (settings, stack, node: ts.EnumMember) => { generators[SyntaxKind.EnumMember] = (settings, stack, node: ts.EnumMember) => {

16
tools/dtsgen/out.d.ts vendored
View file

@ -1,13 +1,5 @@
/* File: /home/wolverindev/TeaSpeak/TeaSpeak/Web-Client/tools/dtsgen/test/test_03.ts */ /* File: /home/wolverindev/TeaSpeak/TeaSpeak/Web-Client/tools/dtsgen/test/test_04.ts */
declare enum YY { type T = "a" | "b" | "c";
H, declare function _t(parm: T);
B declare function __t();
}
declare interface X {
type: any;
c: YY.B;
}
declare class X {
static x();
}

View file

@ -0,0 +1,5 @@
type T = "a" | "b" | "c";
function _t(parm: T) {}
function __t() {}