Skip to content

Commit d69e0b6

Browse files
committed
chore(transformer): Merge isLiteralRuntimeTypeNode and IsLiteralOrPrimitive
1 parent add49a1 commit d69e0b6

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

src/transformer/descriptor/helper/helper.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ type Declaration = ts.InterfaceDeclaration | ts.ClassDeclaration | ts.TypeAliasD
66
type ImportDeclaration = ts.ImportEqualsDeclaration | ts.ImportOrExportSpecifier | ts.ImportClause;
77

88
export namespace TypescriptHelper {
9-
export function IsLiteralOrPrimitive(typeNode: ts.Node): boolean {
10-
return ts.isLiteralTypeNode(typeNode) ||
11-
typeNode.kind === ts.SyntaxKind.StringKeyword ||
12-
typeNode.kind === ts.SyntaxKind.BooleanKeyword ||
13-
typeNode.kind === ts.SyntaxKind.NumberKeyword ||
14-
typeNode.kind === ts.SyntaxKind.ArrayType;
9+
export interface PrimitiveTypeNode extends ts.TypeNode {
10+
kind: ts.SyntaxKind.LiteralType | ts.SyntaxKind.NumberKeyword | ts.SyntaxKind.ObjectKeyword | ts.SyntaxKind.BooleanKeyword | ts.SyntaxKind.StringKeyword | ts.SyntaxKind.ArrayType;
11+
}
12+
13+
export function IsLiteralOrPrimitive(typeNode: ts.Node): typeNode is PrimitiveTypeNode {
14+
switch (typeNode.kind) {
15+
case ts.SyntaxKind.LiteralType:
16+
case ts.SyntaxKind.NumberKeyword:
17+
case ts.SyntaxKind.ObjectKeyword:
18+
case ts.SyntaxKind.BooleanKeyword:
19+
case ts.SyntaxKind.StringKeyword:
20+
case ts.SyntaxKind.ArrayType:
21+
return true;
22+
}
23+
24+
return false;
1525
}
1626

1727
export function GetDeclarationFromNode(node: ts.Node): ts.Declaration {
@@ -119,22 +129,6 @@ export namespace TypescriptHelper {
119129
return !!((symbol.flags & ts.SymbolFlags.Alias) || (symbol.flags & ts.SymbolFlags.AliasExcludes));
120130
}
121131

122-
export interface RuntimeTypeNode extends ts.TypeNode {
123-
kind: ts.SyntaxKind.NumberKeyword | ts.SyntaxKind.ObjectKeyword | ts.SyntaxKind.BooleanKeyword | ts.SyntaxKind.StringKeyword | ts.SyntaxKind.UndefinedKeyword;
124-
}
125-
126-
export function isLiteralRuntimeTypeNode(typeNode: ts.TypeNode): typeNode is RuntimeTypeNode {
127-
switch (typeNode.kind) {
128-
case ts.SyntaxKind.NumberKeyword:
129-
case ts.SyntaxKind.ObjectKeyword:
130-
case ts.SyntaxKind.BooleanKeyword:
131-
case ts.SyntaxKind.StringKeyword:
132-
return true;
133-
}
134-
135-
return false;
136-
}
137-
138132
function isImportExportDeclaration(declaration: ts.Declaration): declaration is ImportDeclaration {
139133
return ts.isImportEqualsDeclaration(declaration) || ts.isImportOrExportSpecifier(declaration) || ts.isImportClause(declaration);
140134
}

src/transformer/descriptor/method/method.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function CreateTypeEquality(signatureType: ts.TypeNode | undefined, primaryDecla
5454
);
5555
}
5656

57-
if (TypescriptHelper.isLiteralRuntimeTypeNode(signatureType)) {
57+
if (TypescriptHelper.IsLiteralOrPrimitive(signatureType)) {
5858
return ts.createStrictEquality(
5959
ts.createTypeOf(identifier),
6060
signatureType ? ts.createStringLiteral(signatureType.getText()) : ts.createVoidZero(),

0 commit comments

Comments
 (0)