Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Accept new baselines
  • Loading branch information
ahejlsberg committed Mar 31, 2019
commit 3e09d29b959be371c98c5c89686c2345bac96442
3 changes: 2 additions & 1 deletion tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2359,7 +2359,8 @@ declare namespace ts {
objectType: Type;
indexType: Type;
constraint?: Type;
simplified?: Type;
simplifiedForReading?: Type;
simplifiedForWriting?: Type;
}
type TypeVariable = TypeParameter | IndexedAccessType;
interface IndexType extends InstantiableType {
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2359,7 +2359,8 @@ declare namespace ts {
objectType: Type;
indexType: Type;
constraint?: Type;
simplified?: Type;
simplifiedForReading?: Type;
simplifiedForWriting?: Type;
}
type TypeVariable = TypeParameter | IndexedAccessType;
interface IndexType extends InstantiableType {
Expand Down
11 changes: 1 addition & 10 deletions tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,9 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(117,5): error
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(122,5): error TS2322: Type '42' is not assignable to type 'keyof T'.
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(123,5): error TS2322: Type '"hello"' is not assignable to type 'keyof T'.
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(140,5): error TS2322: Type '42' is not assignable to type 'T[K]'.
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(141,5): error TS2322: Type '"hello"' is not assignable to type 'T[K]'.
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(142,5): error TS2322: Type 'number[]' is not assignable to type 'T[K]'.


==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (41 errors) ====
==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (38 errors) ====
class Shape {
name: string;
width: number;
Expand Down Expand Up @@ -312,14 +309,8 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(142,5): error

function test1<T extends Record<string, any>, K extends keyof T>(t: T, k: K) {
t[k] = 42; // Error
~~~~
!!! error TS2322: Type '42' is not assignable to type 'T[K]'.
t[k] = "hello"; // Error
~~~~
!!! error TS2322: Type '"hello"' is not assignable to type 'T[K]'.
t[k] = [10, 20]; // Error
~~~~
!!! error TS2322: Type 'number[]' is not assignable to type 'T[K]'.
}

// Repro from #28839
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/keyofAndIndexedAccessErrors.types
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ function f20<T, U>(x: T | U, y: T & U, k1: keyof (T | U), k2: keyof T & keyof U,
>k2 : keyof T & keyof U

x[k3]; // Error
>x[k3] : (T | U)[keyof T | keyof U]
>x[k3] : any
>x : T | U
>k3 : keyof T | keyof U

x[k4]; // Error
>x[k4] : (T | U)[keyof T | keyof U]
>x[k4] : any
>x : T | U
>k4 : keyof T | keyof U

Expand Down
5 changes: 1 addition & 4 deletions tests/baselines/reference/mappedTypeErrors2.errors.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(9,30): error TS2536: Type 'K' cannot be used to index type 'T1<K>'.
tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(13,30): error TS2536: Type 'K' cannot be used to index type 'T3'.
tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(15,38): error TS2536: Type 'S' cannot be used to index type '{ [key in AB[S]]: true; }'.
tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(15,47): error TS2322: Type 'AB[S]' is not assignable to type 'string | number | symbol'.
Type 'AB[S]' is not assignable to type 'symbol'.
tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(15,47): error TS2536: Type 'S' cannot be used to index type 'AB'.
tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(17,49): error TS2536: Type 'L' cannot be used to index type '{ [key in AB[S]]: true; }'.


==== tests/cases/conformance/types/mapped/mappedTypeErrors2.ts (6 errors) ====
==== tests/cases/conformance/types/mapped/mappedTypeErrors2.ts (5 errors) ====
// Repros from #17238

type AB = {
Expand All @@ -27,8 +26,6 @@ tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(17,49): error TS2536:
!!! error TS2536: Type 'K' cannot be used to index type 'T3'.

type T5<S extends 'a'|'b'|'extra'> = {[key in AB[S]]: true}[S]; // Error
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2536: Type 'S' cannot be used to index type '{ [key in AB[S]]: true; }'.
~~~~~
!!! error TS2322: Type 'AB[S]' is not assignable to type 'string | number | symbol'.
!!! error TS2322: Type 'AB[S]' is not assignable to type 'symbol'.
Expand Down
12 changes: 1 addition & 11 deletions tests/baselines/reference/mappedTypeRelationships.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(11,5): error TS2
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(16,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(20,5): error TS2536: Type 'keyof U' cannot be used to index type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(21,5): error TS2322: Type 'T[keyof U]' is not assignable to type 'U[keyof U]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(21,12): error TS2536: Type 'keyof U' cannot be used to index type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(25,5): error TS2536: Type 'K' cannot be used to index type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(26,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(26,12): error TS2536: Type 'K' cannot be used to index type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(30,5): error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'.
Type 'undefined' is not assignable to type 'T[keyof T]'.
Expand Down Expand Up @@ -60,7 +56,7 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS
Type 'T' is not assignable to type 'U'.


==== tests/cases/conformance/types/mapped/mappedTypeRelationships.ts (30 errors) ====
==== tests/cases/conformance/types/mapped/mappedTypeRelationships.ts (28 errors) ====
function f1<T>(x: T, k: keyof T) {
return x[k];
}
Expand Down Expand Up @@ -90,9 +86,6 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS
~~~~
!!! error TS2536: Type 'keyof U' cannot be used to index type 'T'.
y[k] = x[k]; // Error
~~~~
!!! error TS2322: Type 'T[keyof U]' is not assignable to type 'U[keyof U]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
~~~~
!!! error TS2536: Type 'keyof U' cannot be used to index type 'T'.
}
Expand All @@ -102,9 +95,6 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS
~~~~
!!! error TS2536: Type 'K' cannot be used to index type 'T'.
y[k] = x[k]; // Error
~~~~
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
~~~~
!!! error TS2536: Type 'K' cannot be used to index type 'T'.
}
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/mappedTypeRelationships.types
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ function f5<T, U extends T>(x: T, y: U, k: keyof U) {

x[k] = y[k]; // Error
>x[k] = y[k] : U[keyof U]
>x[k] : T[keyof U]
>x[k] : any
>x : T
>k : keyof U
>y[k] : U[keyof U]
>y : U
>k : keyof U

y[k] = x[k]; // Error
>y[k] = x[k] : T[keyof U]
>y[k] = x[k] : any
>y[k] : U[keyof U]
>y : U
>k : keyof U
>x[k] : T[keyof U]
>x[k] : any
>x : T
>k : keyof U
}
Expand All @@ -104,19 +104,19 @@ function f6<T, U extends T, K extends keyof U>(x: T, y: U, k: K) {

x[k] = y[k]; // Error
>x[k] = y[k] : U[K]
>x[k] : T[K]
>x[k] : any
>x : T
>k : K
>y[k] : U[K]
>y : U
>k : K

y[k] = x[k]; // Error
>y[k] = x[k] : T[K]
>y[k] = x[k] : any
>y[k] : U[K]
>y : U
>k : K
>x[k] : T[K]
>x[k] : any
>x : T
>k : K
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessTy
tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts(12,5): error TS2322: Type 'string' is not assignable to type 'T[P]'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts(15,5): error TS2322: Type 'string' is not assignable to type 'T[P]'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts(18,5): error TS2322: Type 'string' is not assignable to type 'T[P]'.
Type 'string' is not assignable to type 'T["toString"] & T["toFixed"] & T["toExponential"] & T["toPrecision"] & T["valueOf"] & T["toLocaleString"]'.
Type 'string' is not assignable to type 'T["toString"]'.
Type 'string' is not assignable to type '(radix?: number | undefined) => string'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts(21,5): error TS2322: Type 'string' is not assignable to type 'T[P]'.
Type 'string' is not assignable to type 'T[number] & T["toString"] & T["valueOf"] & T["charAt"] & T["charCodeAt"] & T["concat"] & T["indexOf"] & T["lastIndexOf"] & T["localeCompare"] & T["match"] & T["replace"] & T["search"] & T["slice"] & T["split"] & T["substring"] & T["toLowerCase"] & T["toLocaleLowerCase"] & T["toUpperCase"] & T["toLocaleUpperCase"] & T["trim"] & T["length"] & T["substr"]'.
Type 'string' is not assignable to type 'T["toString"]'.
Type 'string' is not assignable to type '() => string'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts(24,5): error TS2322: Type 'string' is not assignable to type 'T[P]'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts(27,5): error TS2322: Type 'string' is not assignable to type 'T[P]'.
Type 'string' is not assignable to type 'T["a"]'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts(30,5): error TS2322: Type 'string' is not assignable to type 'T[P]'.
Type 'string' is not assignable to type 'T[string] & T[number]'.
Type 'string' is not assignable to type 'T[string]'.
Type 'string' is not assignable to type 'number'.


==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts (10 errors) ====
Expand Down Expand Up @@ -41,11 +52,17 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessTy
tp = s;
~~
!!! error TS2322: Type 'string' is not assignable to type 'T[P]'.
!!! error TS2322: Type 'string' is not assignable to type 'T["toString"] & T["toFixed"] & T["toExponential"] & T["toPrecision"] & T["valueOf"] & T["toLocaleString"]'.
!!! error TS2322: Type 'string' is not assignable to type 'T["toString"]'.
!!! error TS2322: Type 'string' is not assignable to type '(radix?: number | undefined) => string'.
}
function o<T extends string, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
~~
!!! error TS2322: Type 'string' is not assignable to type 'T[P]'.
!!! error TS2322: Type 'string' is not assignable to type 'T[number] & T["toString"] & T["valueOf"] & T["charAt"] & T["charCodeAt"] & T["concat"] & T["indexOf"] & T["lastIndexOf"] & T["localeCompare"] & T["match"] & T["replace"] & T["search"] & T["slice"] & T["split"] & T["substring"] & T["toLowerCase"] & T["toLocaleLowerCase"] & T["toUpperCase"] & T["toLocaleUpperCase"] & T["trim"] & T["length"] & T["substr"]'.
!!! error TS2322: Type 'string' is not assignable to type 'T["toString"]'.
!!! error TS2322: Type 'string' is not assignable to type '() => string'.
}
function l<T extends {}, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
Expand All @@ -56,10 +73,15 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessTy
tp = s;
~~
!!! error TS2322: Type 'string' is not assignable to type 'T[P]'.
!!! error TS2322: Type 'string' is not assignable to type 'T["a"]'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
}
function n<T extends { [s: string]: number }, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
~~
!!! error TS2322: Type 'string' is not assignable to type 'T[P]'.
!!! error TS2322: Type 'string' is not assignable to type 'T[string] & T[number]'.
!!! error TS2322: Type 'string' is not assignable to type 'T[string]'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
}