0e905be42b
* Switch index signature storage to 'indexInfos: IndexInfo[]' property * Accept new baselines * Remove another usage of IndexKind enum * Update getIndexedAccessType and resolveMappedTypeMembers * Accept new baselines * Update grammar checking for index signatures * Accept new baselines * Consider all index signatures in mapped types and union types * Accept new baselines * Update getIndexType * Accept new baselines * Intersect multiple applicable index signatures * Use getApplicableIndexInfo instead of hardwired string/number handling * Update index signature relationship checking * Report type for which index signature is missing * Report type for which index signature is missing * Accept new baselines * Make 'number' index signatures consistently apply to numeric strings * Accept new baselines * Update fourslash test * Revise index constraint checking * Accept new baselines * Update error messages * Accept new baselines * Update type inference from index signatures * Update isKnownProperty * Update contextual typing based on index signatures * Accept new baselines * Support union types in index signature declarations * Accept new baselines * Check duplicate index signatures / remove redundant template literals from unions with string * Accept new baselines * Include key type in diagnostic / check symbol-named properties * Accept new baselines * Minor fix * Add tests * Accept new baselines * Add optimized findApplicableIndexInfoForName * Accept new baselines * Another place we don't need to obtain literal type for property name * Accept new baselines * Don't create literal types that are going to be discarded * Individual maps for string, number, bigint, and enum literal types * Remove ineffective optimizations * Accept new baselines * Permit intersections as key types in index signatures * Index expression in element access is template literal context * Add tests * Accept new baselines * Symbol index signatures from object literals with computed symbol properties * Accept new baselines * Add more tests * Accept new baselines * Implement Go To Definition for all applicable index signatures * Add fourslash test * Accept new API baselines
113 lines
4.8 KiB
Plaintext
113 lines
4.8 KiB
Plaintext
tests/cases/compiler/readonlyMembers.ts(6,3): error TS2540: Cannot assign to 'a' because it is a read-only property.
|
|
tests/cases/compiler/readonlyMembers.ts(7,3): error TS2540: Cannot assign to 'b' because it is a read-only property.
|
|
tests/cases/compiler/readonlyMembers.ts(16,14): error TS2540: Cannot assign to 'c' because it is a read-only property.
|
|
tests/cases/compiler/readonlyMembers.ts(18,18): error TS2540: Cannot assign to 'a' because it is a read-only property.
|
|
tests/cases/compiler/readonlyMembers.ts(19,18): error TS2540: Cannot assign to 'b' because it is a read-only property.
|
|
tests/cases/compiler/readonlyMembers.ts(20,18): error TS2540: Cannot assign to 'c' because it is a read-only property.
|
|
tests/cases/compiler/readonlyMembers.ts(24,14): error TS2540: Cannot assign to 'a' because it is a read-only property.
|
|
tests/cases/compiler/readonlyMembers.ts(25,14): error TS2540: Cannot assign to 'b' because it is a read-only property.
|
|
tests/cases/compiler/readonlyMembers.ts(26,14): error TS2540: Cannot assign to 'c' because it is a read-only property.
|
|
tests/cases/compiler/readonlyMembers.ts(35,3): error TS2540: Cannot assign to 'a' because it is a read-only property.
|
|
tests/cases/compiler/readonlyMembers.ts(39,3): error TS2540: Cannot assign to 'a' because it is a read-only property.
|
|
tests/cases/compiler/readonlyMembers.ts(48,3): error TS2540: Cannot assign to 'A' because it is a read-only property.
|
|
tests/cases/compiler/readonlyMembers.ts(55,3): error TS2540: Cannot assign to 'a' because it is a read-only property.
|
|
tests/cases/compiler/readonlyMembers.ts(61,1): error TS2542: Index signature in type '{ readonly [x: string]: string; }' only permits reading.
|
|
tests/cases/compiler/readonlyMembers.ts(64,1): error TS2542: Index signature in type '{ readonly [x: number]: string; [x: string]: string; }' only permits reading.
|
|
|
|
|
|
==== tests/cases/compiler/readonlyMembers.ts (15 errors) ====
|
|
interface X {
|
|
readonly a: number;
|
|
readonly b?: number;
|
|
}
|
|
var x: X = { a: 0 };
|
|
x.a = 1; // Error
|
|
~
|
|
!!! error TS2540: Cannot assign to 'a' because it is a read-only property.
|
|
x.b = 1; // Error
|
|
~
|
|
!!! error TS2540: Cannot assign to 'b' because it is a read-only property.
|
|
|
|
class C {
|
|
readonly a: number;
|
|
readonly b = 1;
|
|
get c() { return 1 }
|
|
constructor() {
|
|
this.a = 1; // Ok
|
|
this.b = 1; // Ok
|
|
this.c = 1; // Error
|
|
~
|
|
!!! error TS2540: Cannot assign to 'c' because it is a read-only property.
|
|
const f = () => {
|
|
this.a = 1; // Error
|
|
~
|
|
!!! error TS2540: Cannot assign to 'a' because it is a read-only property.
|
|
this.b = 1; // Error
|
|
~
|
|
!!! error TS2540: Cannot assign to 'b' because it is a read-only property.
|
|
this.c = 1; // Error
|
|
~
|
|
!!! error TS2540: Cannot assign to 'c' because it is a read-only property.
|
|
}
|
|
}
|
|
foo() {
|
|
this.a = 1; // Error
|
|
~
|
|
!!! error TS2540: Cannot assign to 'a' because it is a read-only property.
|
|
this.b = 1; // Error
|
|
~
|
|
!!! error TS2540: Cannot assign to 'b' because it is a read-only property.
|
|
this.c = 1; // Error
|
|
~
|
|
!!! error TS2540: Cannot assign to 'c' because it is a read-only property.
|
|
}
|
|
}
|
|
|
|
var o = {
|
|
get a() { return 1 },
|
|
get b() { return 1 },
|
|
set b(value) { }
|
|
};
|
|
o.a = 1; // Error
|
|
~
|
|
!!! error TS2540: Cannot assign to 'a' because it is a read-only property.
|
|
o.b = 1;
|
|
|
|
var p: { readonly a: number, b: number } = { a: 1, b: 1 };
|
|
p.a = 1; // Error
|
|
~
|
|
!!! error TS2540: Cannot assign to 'a' because it is a read-only property.
|
|
p.b = 1;
|
|
var q: { a: number, b: number } = p;
|
|
q.a = 1;
|
|
q.b = 1;
|
|
|
|
enum E {
|
|
A, B, C
|
|
}
|
|
E.A = 1; // Error
|
|
~
|
|
!!! error TS2540: Cannot assign to 'A' because it is a read-only property.
|
|
|
|
namespace N {
|
|
export const a = 1;
|
|
export let b = 1;
|
|
export var c = 1;
|
|
}
|
|
N.a = 1; // Error
|
|
~
|
|
!!! error TS2540: Cannot assign to 'a' because it is a read-only property.
|
|
N.b = 1;
|
|
N.c = 1;
|
|
|
|
let xx: { readonly [x: string]: string };
|
|
let s = xx["foo"];
|
|
xx["foo"] = "abc"; // Error
|
|
~~~~~~~~~
|
|
!!! error TS2542: Index signature in type '{ readonly [x: string]: string; }' only permits reading.
|
|
|
|
let yy: { readonly [x: number]: string, [x: string]: string };
|
|
yy[1] = "abc"; // Error
|
|
~~~~~
|
|
!!! error TS2542: Index signature in type '{ readonly [x: number]: string; [x: string]: string; }' only permits reading.
|
|
yy["foo"] = "abc"; |