mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-18 13:59:04 -05:00
JSDoc understands string literal types
Unfortunately, I didn't find a way to reuse the normal string literal type, so I had to extend the existing JSDoc type hierarchy. Otherwise, this feature is very simple.
This commit is contained in:
@@ -5326,6 +5326,8 @@ namespace ts {
|
||||
return getTypeFromThisTypeNode(node);
|
||||
case SyntaxKind.StringLiteralType:
|
||||
return getTypeFromStringLiteralTypeNode(<StringLiteralTypeNode>node);
|
||||
case SyntaxKind.JSDocStringLiteralType:
|
||||
return getTypeFromStringLiteralTypeNode((<JSDocStringLiteralType>node).stringLiteral);
|
||||
case SyntaxKind.TypeReference:
|
||||
case SyntaxKind.JSDocTypeReference:
|
||||
return getTypeFromTypeReference(<TypeReferenceNode>node);
|
||||
|
||||
@@ -5860,9 +5860,10 @@ namespace ts {
|
||||
case SyntaxKind.SymbolKeyword:
|
||||
case SyntaxKind.VoidKeyword:
|
||||
return parseTokenNode<JSDocType>();
|
||||
case SyntaxKind.StringLiteral:
|
||||
return parseJSDocStringLiteralType();
|
||||
}
|
||||
|
||||
// TODO (drosen): Parse string literal types in JSDoc as well.
|
||||
return parseJSDocTypeReference();
|
||||
}
|
||||
|
||||
@@ -6041,6 +6042,12 @@ namespace ts {
|
||||
return finishNode(result);
|
||||
}
|
||||
|
||||
function parseJSDocStringLiteralType(): JSDocStringLiteralType {
|
||||
const result = <JSDocStringLiteralType>createNode(SyntaxKind.JSDocStringLiteralType);
|
||||
result.stringLiteral = parseStringLiteralTypeNode();
|
||||
return finishNode(result);
|
||||
}
|
||||
|
||||
function parseJSDocUnknownOrNullableType(): JSDocUnknownType | JSDocNullableType {
|
||||
const pos = scanner.getStartPos();
|
||||
// skip the ?
|
||||
|
||||
@@ -346,6 +346,7 @@ namespace ts {
|
||||
JSDocTypedefTag,
|
||||
JSDocPropertyTag,
|
||||
JSDocTypeLiteral,
|
||||
JSDocStringLiteralType,
|
||||
|
||||
// Synthesized list
|
||||
SyntaxList,
|
||||
@@ -1491,6 +1492,10 @@ namespace ts {
|
||||
type: JSDocType;
|
||||
}
|
||||
|
||||
export interface JSDocStringLiteralType extends JSDocType {
|
||||
stringLiteral: StringLiteralTypeNode;
|
||||
}
|
||||
|
||||
export type JSDocTypeReferencingNode = JSDocThisType | JSDocConstructorType | JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType;
|
||||
|
||||
// @kind(SyntaxKind.JSDocRecordMember)
|
||||
|
||||
Reference in New Issue
Block a user