From 3a1fb1bea6c489771630af95e56882bc4a2386ae Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 11 Jun 2019 09:25:00 -0700 Subject: [PATCH 1/2] Properly preserve CheckFlags.Readonly when widening properties --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ff2360d57a0..2e7c89f235a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14630,7 +14630,7 @@ namespace ts { } function createSymbolWithType(source: Symbol, type: Type | undefined) { - const symbol = createSymbol(source.flags, source.escapedName); + const symbol = createSymbol(source.flags, source.escapedName, getCheckFlags(source) & CheckFlags.Readonly); symbol.declarations = source.declarations; symbol.parent = source.parent; symbol.type = type; From 0ca078b345a7e95dff602292df2f55a99cb64b85 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 11 Jun 2019 09:25:23 -0700 Subject: [PATCH 2/2] Accept new baselines --- tests/baselines/reference/constAssertions.js | 4 ++-- tests/baselines/reference/constAssertions.types | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/constAssertions.js b/tests/baselines/reference/constAssertions.js index 9f173987d22..21369cb3423 100644 --- a/tests/baselines/reference/constAssertions.js +++ b/tests/baselines/reference/constAssertions.js @@ -200,8 +200,8 @@ declare let p4: readonly [readonly [readonly [readonly [10]]]]; declare let x1: { readonly x: 10; readonly y: readonly [20, 30]; - z: { - a: { + readonly z: { + readonly a: { readonly b: 42; }; }; diff --git a/tests/baselines/reference/constAssertions.types b/tests/baselines/reference/constAssertions.types index b1f90df15f0..b02988aea1b 100644 --- a/tests/baselines/reference/constAssertions.types +++ b/tests/baselines/reference/constAssertions.types @@ -281,7 +281,7 @@ let p4 = [[[[10]]]] as const; >10 : 10 let x1 = { x: 10, y: [20, 30], z: { a: { b: 42 } } } as const; ->x1 : { readonly x: 10; readonly y: readonly [20, 30]; z: { a: { readonly b: 42; }; }; } +>x1 : { readonly x: 10; readonly y: readonly [20, 30]; readonly z: { readonly a: { readonly b: 42; }; }; } >{ x: 10, y: [20, 30], z: { a: { b: 42 } } } as const : { readonly x: 10; readonly y: readonly [20, 30]; readonly z: { readonly a: { readonly b: 42; }; }; } >{ x: 10, y: [20, 30], z: { a: { b: 42 } } } : { readonly x: 10; readonly y: readonly [20, 30]; readonly z: { readonly a: { readonly b: 42; }; }; } >x : 10