From 201100dd3cf48005757cb9d3f5643e9ccaa9d82d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 16 Jul 2017 14:44:05 -1000 Subject: [PATCH] Add type-to-string support for 'this: readonly' annotations --- src/compiler/checker.ts | 8 ++++---- src/compiler/types.ts | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c7d72a1650a..432e6721308 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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" : (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 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 385086c7cf3..a042f08f22c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -915,7 +915,8 @@ namespace ts { | SyntaxKind.VoidKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.NullKeyword - | SyntaxKind.NeverKeyword; + | SyntaxKind.NeverKeyword + | SyntaxKind.ReadonlyKeyword; } export interface ThisTypeNode extends TypeNode {