@@ -6,16 +6,16 @@ enforceReadonly1.ts(17,5): error TS2322: Type 'T' is not assignable to type 'Mut
66enforceReadonly1.ts(18,5): error TS2322: Type 'Readonly<T>' is not assignable to type 'Mutable<T>'.
77enforceReadonly1.ts(20,5): error TS2322: Type 'Readonly<T>' is not assignable to type 'T'.
88 'T' could be instantiated with an arbitrary type which could be unrelated to 'Readonly<T>'.
9- enforceReadonly1.ts(31,11): error TS2430: Interface 'D1' incorrectly extends interface 'B1'.
9+ enforceReadonly1.ts(29,5): error TS2322: Type '{ readonly foo: () => void; }' is not assignable to type '{ foo: () => void; }'.
10+ Property 'foo' is 'readonly' in the source but not in the target.
11+ enforceReadonly1.ts(44,11): error TS2430: Interface 'D1' incorrectly extends interface 'B1'.
1012 Property 'x' is 'readonly' in the source but not in the target.
11- enforceReadonly1.ts(40 ,11): error TS2430: Interface 'D2' incorrectly extends interface 'B2'.
13+ enforceReadonly1.ts(53 ,11): error TS2430: Interface 'D2' incorrectly extends interface 'B2'.
1214 Property 'x' is 'readonly' in the source but not in the target.
13- enforceReadonly1.ts(48 ,7): error TS2415: Class 'D3' incorrectly extends base class 'B3'.
15+ enforceReadonly1.ts(61 ,7): error TS2415: Class 'D3' incorrectly extends base class 'B3'.
1416 Property 'x' is 'readonly' in the source but not in the target.
15- enforceReadonly1.ts(56,7): error TS2415: Class 'D4' incorrectly extends base class 'B4'.
16- Property 'foo' is 'readonly' in the source but not in the target.
17- enforceReadonly1.ts(95,3): error TS2540: Cannot assign to 'value' because it is a read-only property.
18- enforceReadonly1.ts(97,5): error TS2322: Type 'ImmutableValue<string>' is not assignable to type 'MutableValue<string>'.
17+ enforceReadonly1.ts(108,3): error TS2540: Cannot assign to 'value' because it is a read-only property.
18+ enforceReadonly1.ts(110,5): error TS2322: Type 'ImmutableValue<string>' is not assignable to type 'MutableValue<string>'.
1919 Property 'value' is 'readonly' in the source but not in the target.
2020
2121
@@ -58,6 +58,22 @@ enforceReadonly1.ts(97,5): error TS2322: Type 'ImmutableValue<string>' is not as
5858 rt = tt;
5959 }
6060
61+ // A read-only property is assignable to a property declared as a method
62+
63+ function f3(m: { foo(): void }, p: { foo: () => void }, r: { readonly foo: () => void }) {
64+ m = r;
65+ p = r; // Error
66+ ~
67+ !!! error TS2322: Type '{ readonly foo: () => void; }' is not assignable to type '{ foo: () => void; }'.
68+ !!! error TS2322: Property 'foo' is 'readonly' in the source but not in the target.
69+ }
70+
71+ type Paths = string[] & { __brand__: "Paths" };
72+
73+ function f4(rp: Readonly<Paths>, rs: Readonly<string[]>) {
74+ rs = rp;
75+ }
76+
6177 // A derived interface may not change property from mutable to read-only
6278
6379 interface B1 {
@@ -99,9 +115,6 @@ enforceReadonly1.ts(97,5): error TS2322: Type 'ImmutableValue<string>' is not as
99115 }
100116
101117 class D4 extends B4 { // Error
102- ~~
103- !!! error TS2415: Class 'D4' incorrectly extends base class 'B4'.
104- !!! error TS2415: Property 'foo' is 'readonly' in the source but not in the target.
105118 readonly foo = () => {}
106119 }
107120
0 commit comments