diff --git a/src/transformer/descriptor/helper/helper.ts b/src/transformer/descriptor/helper/helper.ts index e79fa7793..f5dd14465 100644 --- a/src/transformer/descriptor/helper/helper.ts +++ b/src/transformer/descriptor/helper/helper.ts @@ -6,12 +6,22 @@ type Declaration = ts.InterfaceDeclaration | ts.ClassDeclaration | ts.TypeAliasD type ImportDeclaration = ts.ImportEqualsDeclaration | ts.ImportOrExportSpecifier | ts.ImportClause; export namespace TypescriptHelper { - export function IsLiteralOrPrimitive(typeNode: ts.Node): boolean { - return ts.isLiteralTypeNode(typeNode) || - typeNode.kind === ts.SyntaxKind.StringKeyword || - typeNode.kind === ts.SyntaxKind.BooleanKeyword || - typeNode.kind === ts.SyntaxKind.NumberKeyword || - typeNode.kind === ts.SyntaxKind.ArrayType; + export interface PrimitiveTypeNode extends ts.TypeNode { + kind: ts.SyntaxKind.LiteralType | ts.SyntaxKind.NumberKeyword | ts.SyntaxKind.ObjectKeyword | ts.SyntaxKind.BooleanKeyword | ts.SyntaxKind.StringKeyword | ts.SyntaxKind.ArrayType; + } + + export function IsLiteralOrPrimitive(typeNode: ts.Node): typeNode is PrimitiveTypeNode { + switch (typeNode.kind) { + case ts.SyntaxKind.LiteralType: + case ts.SyntaxKind.NumberKeyword: + case ts.SyntaxKind.ObjectKeyword: + case ts.SyntaxKind.BooleanKeyword: + case ts.SyntaxKind.StringKeyword: + case ts.SyntaxKind.ArrayType: + return true; + } + + return false; } export function GetDeclarationFromNode(node: ts.Node): ts.Declaration { @@ -119,22 +129,6 @@ export namespace TypescriptHelper { return !!((symbol.flags & ts.SymbolFlags.Alias) || (symbol.flags & ts.SymbolFlags.AliasExcludes)); } - export interface RuntimeTypeNode extends ts.TypeNode { - kind: ts.SyntaxKind.NumberKeyword | ts.SyntaxKind.ObjectKeyword | ts.SyntaxKind.BooleanKeyword | ts.SyntaxKind.StringKeyword | ts.SyntaxKind.UndefinedKeyword; - } - - export function isLiteralRuntimeTypeNode(typeNode: ts.TypeNode): typeNode is RuntimeTypeNode { - switch (typeNode.kind) { - case ts.SyntaxKind.NumberKeyword: - case ts.SyntaxKind.ObjectKeyword: - case ts.SyntaxKind.BooleanKeyword: - case ts.SyntaxKind.StringKeyword: - return true; - } - - return false; - } - function isImportExportDeclaration(declaration: ts.Declaration): declaration is ImportDeclaration { return ts.isImportEqualsDeclaration(declaration) || ts.isImportOrExportSpecifier(declaration) || ts.isImportClause(declaration); } diff --git a/src/transformer/descriptor/method/method.ts b/src/transformer/descriptor/method/method.ts index 1bddcf351..6e0eaeda8 100644 --- a/src/transformer/descriptor/method/method.ts +++ b/src/transformer/descriptor/method/method.ts @@ -54,7 +54,7 @@ function CreateTypeEquality(signatureType: ts.TypeNode | undefined, primaryDecla ); } - if (TypescriptHelper.isLiteralRuntimeTypeNode(signatureType)) { + if (TypescriptHelper.IsLiteralOrPrimitive(signatureType)) { return ts.createStrictEquality( ts.createTypeOf(identifier), signatureType ? ts.createStringLiteral(signatureType.getText()) : ts.createVoidZero(),