Readonly type literal members
This commit is contained in:
parent
7e2517975c
commit
55388d16b4
3 changed files with 14 additions and 7 deletions
|
@ -2602,14 +2602,17 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// TODO(aozgaa): should we create a node with explicit or implict any?
|
||||
const propertyTypeNode = propertyType ? typeToTypeNodeHelper(propertyType, context) : createKeywordTypeNode(SyntaxKind.AnyKeyword);
|
||||
typeElements.push(createPropertySignature(
|
||||
|
||||
const modifiers = isReadonlySymbol(propertySymbol) ? [createToken(SyntaxKind.ReadonlyKeyword)] : undefined;
|
||||
const propertySignature = createPropertySignature(
|
||||
modifiers,
|
||||
propertyName,
|
||||
optionalToken,
|
||||
propertyTypeNode,
|
||||
/*initializer*/undefined));
|
||||
/*initializer*/undefined);
|
||||
typeElements.push(propertySignature);
|
||||
}
|
||||
}
|
||||
return typeElements.length ? typeElements : undefined;
|
||||
|
|
|
@ -480,8 +480,9 @@ namespace ts {
|
|||
|
||||
// Signature elements
|
||||
|
||||
export function createPropertySignature(name: PropertyName | string, questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): PropertySignature {
|
||||
export function createPropertySignature(modifiers: Modifier[] | undefined, name: PropertyName | string, questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): PropertySignature {
|
||||
const propertySignature = createSynthesizedNode(SyntaxKind.PropertySignature) as PropertySignature;
|
||||
propertySignature.modifiers = asNodeArray(modifiers);
|
||||
propertySignature.name = asName(name);
|
||||
propertySignature.questionToken = questionToken;
|
||||
propertySignature.type = type;
|
||||
|
@ -489,12 +490,13 @@ namespace ts {
|
|||
return propertySignature;
|
||||
}
|
||||
|
||||
export function updatePropertySignature(node: PropertySignature, name: PropertyName, questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined) {
|
||||
return node.name !== name
|
||||
export function updatePropertySignature(node: PropertySignature, modifiers: Modifier[] | undefined, name: PropertyName, questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined) {
|
||||
return node.modifiers !== modifiers
|
||||
|| node.name !== name
|
||||
|| node.questionToken !== questionToken
|
||||
|| node.type !== type
|
||||
|| node.initializer !== initializer
|
||||
? updateNode(createPropertySignature(name, questionToken, type, initializer), node)
|
||||
? updateNode(createPropertySignature(modifiers, name, questionToken, type, initializer), node)
|
||||
: node;
|
||||
}
|
||||
|
||||
|
|
|
@ -355,6 +355,8 @@ namespace ts {
|
|||
|
||||
case SyntaxKind.PropertySignature:
|
||||
return updatePropertySignature((<PropertySignature>node),
|
||||
// TODO: tokenVisitor or visitor for a nodearray of tokens?
|
||||
nodesVisitor((<PropertySignature>node).modifiers, visitor, isToken),
|
||||
visitNode((<PropertySignature>node).name, visitor, isPropertyName),
|
||||
visitNode((<PropertySignature>node).questionToken, tokenVisitor, isToken),
|
||||
visitNode((<PropertySignature>node).type, visitor, isTypeNode),
|
||||
|
|
Loading…
Reference in a new issue