Add type-to-string support for 'this: readonly' annotations

This commit is contained in:
Anders Hejlsberg 2017-07-16 14:44:05 -10:00
parent 73b1c7167a
commit 201100dd3c
2 changed files with 6 additions and 5 deletions

View File

@ -2395,7 +2395,7 @@ namespace ts {
}
if (type.flags & TypeFlags.Any) {
return createKeywordTypeNode(SyntaxKind.AnyKeyword);
return createKeywordTypeNode(type !== readonlyThisType ? SyntaxKind.AnyKeyword : SyntaxKind.ReadonlyKeyword);
}
if (type.flags & TypeFlags.String) {
return createKeywordTypeNode(SyntaxKind.StringKeyword);
@ -3212,7 +3212,7 @@ namespace ts {
// Write undefined/null type as any
if (type.flags & TypeFlags.Intrinsic) {
// Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving
writer.writeKeyword(!(globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike) && isTypeAny(type)
writer.writeKeyword(!(globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike) && isTypeAny(type) && type !== readonlyThisType
? "any"
: (<IntrinsicType>type).intrinsicName);
}
@ -5515,8 +5515,8 @@ namespace ts {
// Union the result types when more than one signature matches
if (unionSignatures.length > 1) {
s = cloneSignature(signature);
if (forEach(unionSignatures, sig => sig.thisParameter)) {
const thisType = getUnionType(map(unionSignatures, sig => getTypeOfSymbol(sig.thisParameter) || anyType), /*subtypeReduction*/ true);
if (forEach(unionSignatures, sig => getThisTypeOfSignature(sig))) {
const thisType = getUnionType(map(unionSignatures, sig => getThisTypeOfSignature(sig)), /*subtypeReduction*/ true);
s.thisParameter = createSymbolWithType(signature.thisParameter, thisType);
}
// Clear resolved return type we possibly got from cloneSignature

View File

@ -915,7 +915,8 @@ namespace ts {
| SyntaxKind.VoidKeyword
| SyntaxKind.UndefinedKeyword
| SyntaxKind.NullKeyword
| SyntaxKind.NeverKeyword;
| SyntaxKind.NeverKeyword
| SyntaxKind.ReadonlyKeyword;
}
export interface ThisTypeNode extends TypeNode {