mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-21 13:14:43 -06:00
Fixed a mistake, whereby the check for the literal type was satisfied when any (not every) was a literal
This commit is contained in:
parent
a0d827cfdf
commit
92bffe43c5
@ -25781,7 +25781,7 @@ namespace ts {
|
||||
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_cannot_be_a_type_alias_Use_index_Colon_0_instead, typeToString(type));
|
||||
}
|
||||
|
||||
if (type.flags & TypeFlags.Union && forEach((<UnionType>type).types, t => !!(t.flags & TypeFlags.StringOrNumberLiteral))) {
|
||||
if (type.flags & TypeFlags.Union && every((<UnionType>type).types, t => !!(t.flags & TypeFlags.StringOrNumberLiteral))) {
|
||||
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_cannot_be_a_union_type_Use_K_in_0_instead, symbolName(type.aliasSymbol));
|
||||
}
|
||||
|
||||
|
||||
@ -7,9 +7,11 @@ tests/cases/compiler/indexerConstraints2.ts(46,6): error TS1023: An index signat
|
||||
tests/cases/compiler/indexerConstraints2.ts(52,6): error TS1337: An index signature parameter type cannot be a union type. Use '[K in IndexableUnion]' instead.
|
||||
tests/cases/compiler/indexerConstraints2.ts(58,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
|
||||
tests/cases/compiler/indexerConstraints2.ts(64,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
|
||||
tests/cases/compiler/indexerConstraints2.ts(70,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
|
||||
tests/cases/compiler/indexerConstraints2.ts(76,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/indexerConstraints2.ts (9 errors) ====
|
||||
==== tests/cases/compiler/indexerConstraints2.ts (11 errors) ====
|
||||
class A { a: number; }
|
||||
class B extends A { b: number; }
|
||||
|
||||
@ -91,5 +93,21 @@ tests/cases/compiler/indexerConstraints2.ts(64,6): error TS1023: An index signat
|
||||
interface Q {
|
||||
[u: NonIndexableUnion2]: A;
|
||||
~
|
||||
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
|
||||
}
|
||||
|
||||
type NonIndexableUnion3 = 42 | string;
|
||||
|
||||
interface R {
|
||||
[u: NonIndexableUnion3]: A;
|
||||
~
|
||||
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
|
||||
}
|
||||
|
||||
type NonIndexableUnion4 = "foo" | number;
|
||||
|
||||
interface S {
|
||||
[u: NonIndexableUnion4]: A;
|
||||
~
|
||||
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
|
||||
}
|
||||
@ -63,6 +63,18 @@ type NonIndexableUnion2 = string | number;
|
||||
|
||||
interface Q {
|
||||
[u: NonIndexableUnion2]: A;
|
||||
}
|
||||
|
||||
type NonIndexableUnion3 = 42 | string;
|
||||
|
||||
interface R {
|
||||
[u: NonIndexableUnion3]: A;
|
||||
}
|
||||
|
||||
type NonIndexableUnion4 = "foo" | number;
|
||||
|
||||
interface S {
|
||||
[u: NonIndexableUnion4]: A;
|
||||
}
|
||||
|
||||
//// [indexerConstraints2.js]
|
||||
|
||||
@ -135,3 +135,27 @@ interface Q {
|
||||
>NonIndexableUnion2 : Symbol(NonIndexableUnion2, Decl(indexerConstraints2.ts, 58, 1))
|
||||
>A : Symbol(A, Decl(indexerConstraints2.ts, 0, 0))
|
||||
}
|
||||
|
||||
type NonIndexableUnion3 = 42 | string;
|
||||
>NonIndexableUnion3 : Symbol(NonIndexableUnion3, Decl(indexerConstraints2.ts, 64, 1))
|
||||
|
||||
interface R {
|
||||
>R : Symbol(R, Decl(indexerConstraints2.ts, 66, 38))
|
||||
|
||||
[u: NonIndexableUnion3]: A;
|
||||
>u : Symbol(u, Decl(indexerConstraints2.ts, 69, 5))
|
||||
>NonIndexableUnion3 : Symbol(NonIndexableUnion3, Decl(indexerConstraints2.ts, 64, 1))
|
||||
>A : Symbol(A, Decl(indexerConstraints2.ts, 0, 0))
|
||||
}
|
||||
|
||||
type NonIndexableUnion4 = "foo" | number;
|
||||
>NonIndexableUnion4 : Symbol(NonIndexableUnion4, Decl(indexerConstraints2.ts, 70, 1))
|
||||
|
||||
interface S {
|
||||
>S : Symbol(S, Decl(indexerConstraints2.ts, 72, 41))
|
||||
|
||||
[u: NonIndexableUnion4]: A;
|
||||
>u : Symbol(u, Decl(indexerConstraints2.ts, 75, 5))
|
||||
>NonIndexableUnion4 : Symbol(NonIndexableUnion4, Decl(indexerConstraints2.ts, 70, 1))
|
||||
>A : Symbol(A, Decl(indexerConstraints2.ts, 0, 0))
|
||||
}
|
||||
|
||||
@ -135,3 +135,27 @@ interface Q {
|
||||
>NonIndexableUnion2 : NonIndexableUnion2
|
||||
>A : A
|
||||
}
|
||||
|
||||
type NonIndexableUnion3 = 42 | string;
|
||||
>NonIndexableUnion3 : NonIndexableUnion3
|
||||
|
||||
interface R {
|
||||
>R : R
|
||||
|
||||
[u: NonIndexableUnion3]: A;
|
||||
>u : NonIndexableUnion3
|
||||
>NonIndexableUnion3 : NonIndexableUnion3
|
||||
>A : A
|
||||
}
|
||||
|
||||
type NonIndexableUnion4 = "foo" | number;
|
||||
>NonIndexableUnion4 : NonIndexableUnion4
|
||||
|
||||
interface S {
|
||||
>S : S
|
||||
|
||||
[u: NonIndexableUnion4]: A;
|
||||
>u : NonIndexableUnion4
|
||||
>NonIndexableUnion4 : NonIndexableUnion4
|
||||
>A : A
|
||||
}
|
||||
|
||||
@ -62,4 +62,16 @@ type NonIndexableUnion2 = string | number;
|
||||
|
||||
interface Q {
|
||||
[u: NonIndexableUnion2]: A;
|
||||
}
|
||||
|
||||
type NonIndexableUnion3 = 42 | string;
|
||||
|
||||
interface R {
|
||||
[u: NonIndexableUnion3]: A;
|
||||
}
|
||||
|
||||
type NonIndexableUnion4 = "foo" | number;
|
||||
|
||||
interface S {
|
||||
[u: NonIndexableUnion4]: A;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user