Merge pull request #29665 from ajafff/readonly-error-message
clarify error message for 'readonly' type operator
This commit is contained in:
commit
9d3707d671
7 changed files with 59 additions and 45 deletions
|
@ -30756,7 +30756,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
else if (node.operator === SyntaxKind.ReadonlyKeyword) {
|
else if (node.operator === SyntaxKind.ReadonlyKeyword) {
|
||||||
if (node.type.kind !== SyntaxKind.ArrayType && node.type.kind !== SyntaxKind.TupleType) {
|
if (node.type.kind !== SyntaxKind.ArrayType && node.type.kind !== SyntaxKind.TupleType) {
|
||||||
return grammarErrorOnFirstToken(node, Diagnostics.readonly_type_modifier_is_only_permitted_on_array_and_tuple_types, tokenToString(SyntaxKind.SymbolKeyword));
|
return grammarErrorOnFirstToken(node, Diagnostics.readonly_type_modifier_is_only_permitted_on_array_and_tuple_literal_types, tokenToString(SyntaxKind.SymbolKeyword));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1023,7 +1023,7 @@
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 1353
|
"code": 1353
|
||||||
},
|
},
|
||||||
"'readonly' type modifier is only permitted on array and tuple types.": {
|
"'readonly' type modifier is only permitted on array and tuple literal types.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 1354
|
"code": 1354
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(9,12): error TS1354: 'readonly' type modifier is only permitted on array and tuple types.
|
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(9,12): error TS1354: 'readonly' type modifier is only permitted on array and tuple literal types.
|
||||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(10,15): error TS1354: 'readonly' type modifier is only permitted on array and tuple types.
|
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(10,15): error TS1354: 'readonly' type modifier is only permitted on array and tuple literal types.
|
||||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(11,12): error TS1354: 'readonly' type modifier is only permitted on array and tuple types.
|
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(11,12): error TS1354: 'readonly' type modifier is only permitted on array and tuple literal types.
|
||||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(14,5): error TS2740: Type 'readonly string[]' is missing the following properties from type 'string[]': pop, push, reverse, shift, and 3 more.
|
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(12,12): error TS1354: 'readonly' type modifier is only permitted on array and tuple literal types.
|
||||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(16,5): error TS2740: Type 'readonly [string, string]' is missing the following properties from type 'string[]': pop, push, reverse, shift, and 3 more.
|
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(15,5): error TS2740: Type 'readonly string[]' is missing the following properties from type 'string[]': pop, push, reverse, shift, and 3 more.
|
||||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(20,5): error TS2739: Type 'string[]' is missing the following properties from type '[string, string]': 0, 1
|
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(17,5): error TS2740: Type 'readonly [string, string]' is missing the following properties from type 'string[]': pop, push, reverse, shift, and 3 more.
|
||||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(21,5): error TS2740: Type 'readonly string[]' is missing the following properties from type '[string, string]': 0, 1, pop, push, and 5 more.
|
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(21,5): error TS2739: Type 'string[]' is missing the following properties from type '[string, string]': 0, 1
|
||||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(22,5): error TS2740: Type 'readonly [string, string]' is missing the following properties from type '[string, string]': pop, push, reverse, shift, and 3 more.
|
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(22,5): error TS2740: Type 'readonly string[]' is missing the following properties from type '[string, string]': 0, 1, pop, push, and 5 more.
|
||||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(23,5): error TS2739: Type 'string[]' is missing the following properties from type 'readonly [string, string]': 0, 1
|
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(23,5): error TS2740: Type 'readonly [string, string]' is missing the following properties from type '[string, string]': pop, push, reverse, shift, and 3 more.
|
||||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(24,5): error TS2739: Type 'readonly string[]' is missing the following properties from type 'readonly [string, string]': 0, 1
|
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(24,5): error TS2739: Type 'string[]' is missing the following properties from type 'readonly [string, string]': 0, 1
|
||||||
|
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(25,5): error TS2739: Type 'readonly string[]' is missing the following properties from type 'readonly [string, string]': 0, 1
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts (10 errors) ====
|
==== tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts (11 errors) ====
|
||||||
type T10 = string[];
|
type T10 = string[];
|
||||||
type T11 = Array<string>;
|
type T11 = Array<string>;
|
||||||
type T12 = readonly string[];
|
type T12 = readonly string[];
|
||||||
|
@ -21,13 +22,16 @@ tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(24,5): error TS27
|
||||||
|
|
||||||
type T30 = readonly string; // Error
|
type T30 = readonly string; // Error
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
!!! error TS1354: 'readonly' type modifier is only permitted on array and tuple types.
|
!!! error TS1354: 'readonly' type modifier is only permitted on array and tuple literal types.
|
||||||
type T31<T> = readonly T; // Error
|
type T31<T> = readonly T; // Error
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
!!! error TS1354: 'readonly' type modifier is only permitted on array and tuple types.
|
!!! error TS1354: 'readonly' type modifier is only permitted on array and tuple literal types.
|
||||||
type T32 = readonly readonly string[]; // Error
|
type T32 = readonly readonly string[]; // Error
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
!!! error TS1354: 'readonly' type modifier is only permitted on array and tuple types.
|
!!! error TS1354: 'readonly' type modifier is only permitted on array and tuple literal types.
|
||||||
|
type T33 = readonly Array<string>; // Error
|
||||||
|
~~~~~~~~
|
||||||
|
!!! error TS1354: 'readonly' type modifier is only permitted on array and tuple literal types.
|
||||||
|
|
||||||
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
||||||
ma = ra; // Error
|
ma = ra; // Error
|
||||||
|
|
|
@ -10,6 +10,7 @@ type T21 = readonly [number, number];
|
||||||
type T30 = readonly string; // Error
|
type T30 = readonly string; // Error
|
||||||
type T31<T> = readonly T; // Error
|
type T31<T> = readonly T; // Error
|
||||||
type T32 = readonly readonly string[]; // Error
|
type T32 = readonly readonly string[]; // Error
|
||||||
|
type T33 = readonly Array<string>; // Error
|
||||||
|
|
||||||
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
||||||
ma = ra; // Error
|
ma = ra; // Error
|
||||||
|
@ -55,4 +56,5 @@ declare type T21 = readonly [number, number];
|
||||||
declare type T30 = readonly string;
|
declare type T30 = readonly string;
|
||||||
declare type T31<T> = readonly T;
|
declare type T31<T> = readonly T;
|
||||||
declare type T32 = readonly readonly string[];
|
declare type T32 = readonly readonly string[];
|
||||||
|
declare type T33 = readonly Array<string>;
|
||||||
declare function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]): void;
|
declare function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]): void;
|
||||||
|
|
|
@ -30,59 +30,63 @@ type T31<T> = readonly T; // Error
|
||||||
type T32 = readonly readonly string[]; // Error
|
type T32 = readonly readonly string[]; // Error
|
||||||
>T32 : Symbol(T32, Decl(readonlyArraysAndTuples.ts, 9, 25))
|
>T32 : Symbol(T32, Decl(readonlyArraysAndTuples.ts, 9, 25))
|
||||||
|
|
||||||
|
type T33 = readonly Array<string>; // Error
|
||||||
|
>T33 : Symbol(T33, Decl(readonlyArraysAndTuples.ts, 10, 38))
|
||||||
|
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||||
|
|
||||||
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
||||||
>f1 : Symbol(f1, Decl(readonlyArraysAndTuples.ts, 10, 38))
|
>f1 : Symbol(f1, Decl(readonlyArraysAndTuples.ts, 11, 34))
|
||||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 13, 12))
|
||||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 13, 25))
|
||||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 13, 48))
|
||||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 13, 70))
|
||||||
|
|
||||||
ma = ra; // Error
|
ma = ra; // Error
|
||||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 13, 12))
|
||||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 13, 25))
|
||||||
|
|
||||||
ma = mt;
|
ma = mt;
|
||||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 13, 12))
|
||||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 13, 48))
|
||||||
|
|
||||||
ma = rt; // Error
|
ma = rt; // Error
|
||||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 13, 12))
|
||||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 13, 70))
|
||||||
|
|
||||||
ra = ma;
|
ra = ma;
|
||||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 13, 25))
|
||||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 13, 12))
|
||||||
|
|
||||||
ra = mt;
|
ra = mt;
|
||||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 13, 25))
|
||||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 13, 48))
|
||||||
|
|
||||||
ra = rt;
|
ra = rt;
|
||||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 13, 25))
|
||||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 13, 70))
|
||||||
|
|
||||||
mt = ma; // Error
|
mt = ma; // Error
|
||||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 13, 48))
|
||||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 13, 12))
|
||||||
|
|
||||||
mt = ra; // Error
|
mt = ra; // Error
|
||||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 13, 48))
|
||||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 13, 25))
|
||||||
|
|
||||||
mt = rt; // Error
|
mt = rt; // Error
|
||||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 13, 48))
|
||||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 13, 70))
|
||||||
|
|
||||||
rt = ma; // Error
|
rt = ma; // Error
|
||||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 13, 70))
|
||||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 13, 12))
|
||||||
|
|
||||||
rt = ra; // Error
|
rt = ra; // Error
|
||||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 13, 70))
|
||||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 13, 25))
|
||||||
|
|
||||||
rt = mt;
|
rt = mt;
|
||||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 13, 70))
|
||||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 13, 48))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,9 @@ type T31<T> = readonly T; // Error
|
||||||
type T32 = readonly readonly string[]; // Error
|
type T32 = readonly readonly string[]; // Error
|
||||||
>T32 : readonly string[]
|
>T32 : readonly string[]
|
||||||
|
|
||||||
|
type T33 = readonly Array<string>; // Error
|
||||||
|
>T33 : string[]
|
||||||
|
|
||||||
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
||||||
>f1 : (ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) => void
|
>f1 : (ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) => void
|
||||||
>ma : string[]
|
>ma : string[]
|
||||||
|
|
|
@ -12,6 +12,7 @@ type T21 = readonly [number, number];
|
||||||
type T30 = readonly string; // Error
|
type T30 = readonly string; // Error
|
||||||
type T31<T> = readonly T; // Error
|
type T31<T> = readonly T; // Error
|
||||||
type T32 = readonly readonly string[]; // Error
|
type T32 = readonly readonly string[]; // Error
|
||||||
|
type T33 = readonly Array<string>; // Error
|
||||||
|
|
||||||
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
||||||
ma = ra; // Error
|
ma = ra; // Error
|
||||||
|
|
Loading…
Reference in a new issue