mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fixed an incorrect assumption K in Union works with numeric literals
This commit is contained in:
@@ -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 && every((<UnionType>type).types, t => !!(t.flags & TypeFlags.StringOrNumberLiteral))) {
|
||||
if (type.flags & TypeFlags.Union && every((<UnionType>type).types, t => !!(t.flags & TypeFlags.StringLiteral))) {
|
||||
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_cannot_be_a_union_type_Use_K_in_0_instead, symbolName(type.aliasSymbol));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,9 @@ tests/cases/compiler/indexerConstraints2.ts(52,6): error TS1337: An index signat
|
||||
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 (11 errors) ====
|
||||
==== tests/cases/compiler/indexerConstraints2.ts (10 errors) ====
|
||||
class A { a: number; }
|
||||
class B extends A { b: number; }
|
||||
|
||||
@@ -72,7 +71,7 @@ tests/cases/compiler/indexerConstraints2.ts(76,6): error TS1023: An index signat
|
||||
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
|
||||
}
|
||||
|
||||
type IndexableUnion = "foo" | 42;
|
||||
type IndexableUnion = "foo" | "bar";
|
||||
|
||||
interface O {
|
||||
[u: IndexableUnion]: A;
|
||||
@@ -96,18 +95,10 @@ tests/cases/compiler/indexerConstraints2.ts(76,6): error TS1023: An index signat
|
||||
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
|
||||
}
|
||||
|
||||
type NonIndexableUnion3 = 42 | string;
|
||||
type NonIndexableUnion3 = "foo" | 42;
|
||||
|
||||
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'.
|
||||
}
|
||||
@@ -47,7 +47,7 @@ interface N {
|
||||
[b: AliasedBoolean]: A;
|
||||
}
|
||||
|
||||
type IndexableUnion = "foo" | 42;
|
||||
type IndexableUnion = "foo" | "bar";
|
||||
|
||||
interface O {
|
||||
[u: IndexableUnion]: A;
|
||||
@@ -65,16 +65,10 @@ interface Q {
|
||||
[u: NonIndexableUnion2]: A;
|
||||
}
|
||||
|
||||
type NonIndexableUnion3 = 42 | string;
|
||||
type NonIndexableUnion3 = "foo" | 42;
|
||||
|
||||
interface R {
|
||||
[u: NonIndexableUnion3]: A;
|
||||
}
|
||||
|
||||
type NonIndexableUnion4 = "foo" | number;
|
||||
|
||||
interface S {
|
||||
[u: NonIndexableUnion4]: A;
|
||||
}
|
||||
|
||||
//// [indexerConstraints2.js]
|
||||
|
||||
@@ -100,11 +100,11 @@ interface N {
|
||||
>A : Symbol(A, Decl(indexerConstraints2.ts, 0, 0))
|
||||
}
|
||||
|
||||
type IndexableUnion = "foo" | 42;
|
||||
type IndexableUnion = "foo" | "bar";
|
||||
>IndexableUnion : Symbol(IndexableUnion, Decl(indexerConstraints2.ts, 46, 1))
|
||||
|
||||
interface O {
|
||||
>O : Symbol(O, Decl(indexerConstraints2.ts, 48, 33))
|
||||
>O : Symbol(O, Decl(indexerConstraints2.ts, 48, 36))
|
||||
|
||||
[u: IndexableUnion]: A;
|
||||
>u : Symbol(u, Decl(indexerConstraints2.ts, 51, 5))
|
||||
@@ -136,26 +136,14 @@ interface Q {
|
||||
>A : Symbol(A, Decl(indexerConstraints2.ts, 0, 0))
|
||||
}
|
||||
|
||||
type NonIndexableUnion3 = 42 | string;
|
||||
type NonIndexableUnion3 = "foo" | 42;
|
||||
>NonIndexableUnion3 : Symbol(NonIndexableUnion3, Decl(indexerConstraints2.ts, 64, 1))
|
||||
|
||||
interface R {
|
||||
>R : Symbol(R, Decl(indexerConstraints2.ts, 66, 38))
|
||||
>R : Symbol(R, Decl(indexerConstraints2.ts, 66, 37))
|
||||
|
||||
[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))
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ interface N {
|
||||
>A : A
|
||||
}
|
||||
|
||||
type IndexableUnion = "foo" | 42;
|
||||
type IndexableUnion = "foo" | "bar";
|
||||
>IndexableUnion : IndexableUnion
|
||||
|
||||
interface O {
|
||||
@@ -136,7 +136,7 @@ interface Q {
|
||||
>A : A
|
||||
}
|
||||
|
||||
type NonIndexableUnion3 = 42 | string;
|
||||
type NonIndexableUnion3 = "foo" | 42;
|
||||
>NonIndexableUnion3 : NonIndexableUnion3
|
||||
|
||||
interface R {
|
||||
@@ -147,15 +147,3 @@ interface R {
|
||||
>NonIndexableUnion3 : NonIndexableUnion3
|
||||
>A : A
|
||||
}
|
||||
|
||||
type NonIndexableUnion4 = "foo" | number;
|
||||
>NonIndexableUnion4 : NonIndexableUnion4
|
||||
|
||||
interface S {
|
||||
>S : S
|
||||
|
||||
[u: NonIndexableUnion4]: A;
|
||||
>u : NonIndexableUnion4
|
||||
>NonIndexableUnion4 : NonIndexableUnion4
|
||||
>A : A
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ interface N {
|
||||
[b: AliasedBoolean]: A;
|
||||
}
|
||||
|
||||
type IndexableUnion = "foo" | 42;
|
||||
type IndexableUnion = "foo" | "bar";
|
||||
|
||||
interface O {
|
||||
[u: IndexableUnion]: A;
|
||||
@@ -64,14 +64,8 @@ interface Q {
|
||||
[u: NonIndexableUnion2]: A;
|
||||
}
|
||||
|
||||
type NonIndexableUnion3 = 42 | string;
|
||||
type NonIndexableUnion3 = "foo" | 42;
|
||||
|
||||
interface R {
|
||||
[u: NonIndexableUnion3]: A;
|
||||
}
|
||||
|
||||
type NonIndexableUnion4 = "foo" | number;
|
||||
|
||||
interface S {
|
||||
[u: NonIndexableUnion4]: A;
|
||||
}
|
||||
Reference in New Issue
Block a user