From 0f6bc92683d62ae4307a70c249e3cde901cf34a0 Mon Sep 17 00:00:00 2001 From: SHIMA RYUHEI <65934663+islandryu@users.noreply.github.com> Date: Fri, 24 Feb 2023 08:27:56 +0900 Subject: [PATCH 1/3] Accurate constraintType for indexedAccessType --- src/compiler/checker.ts | 7 +- .../reference/constraintWithIndexedAccess.js | 33 +++++ .../constraintWithIndexedAccess.symbols | 139 ++++++++++++++++++ .../constraintWithIndexedAccess.types | 83 +++++++++++ .../reference/deepComparisons.errors.txt | 30 ++-- .../keyofAndIndexedAccess.errors.txt | 16 +- .../mappedTypeRelationships.errors.txt | 10 +- .../reference/mappedTypes6.errors.txt | 50 ++----- .../compiler/constraintWithIndexedAccess.ts | 27 ++++ 9 files changed, 328 insertions(+), 67 deletions(-) create mode 100644 tests/baselines/reference/constraintWithIndexedAccess.js create mode 100644 tests/baselines/reference/constraintWithIndexedAccess.symbols create mode 100644 tests/baselines/reference/constraintWithIndexedAccess.types create mode 100644 tests/cases/compiler/constraintWithIndexedAccess.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 50cf05bad962d..f68718e8aabe5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13508,7 +13508,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // we substitute an instantiation of E where P is replaced with X. return substituteIndexedMappedType(type.objectType as MappedType, type.indexType); } - const indexConstraint = getSimplifiedTypeOrConstraint(type.indexType); + const indexType = type.indexType; + let indexConstraint = getSimplifiedTypeOrConstraint(indexType); + if (indexConstraint && indexConstraint.flags & TypeFlags.Index) { + const constraint = getBaseConstraintOfType((indexConstraint as IndexType).type); + indexConstraint = constraint && constraint !== noConstraintType ? getIndexType(constraint) : keyofConstraintType; + } if (indexConstraint && indexConstraint !== type.indexType) { const indexedAccess = getIndexedAccessTypeOrUndefined(type.objectType, indexConstraint, type.accessFlags); if (indexedAccess) { diff --git a/tests/baselines/reference/constraintWithIndexedAccess.js b/tests/baselines/reference/constraintWithIndexedAccess.js new file mode 100644 index 0000000000000..a1e779f79667d --- /dev/null +++ b/tests/baselines/reference/constraintWithIndexedAccess.js @@ -0,0 +1,33 @@ +//// [constraintWithIndexedAccess.ts] +// #52399 +type DataFetchFns = { + Boat: { + requiresLicense: (id: string) => boolean; + maxGroundSpeed: (id: string) => number; + description: (id: string) => string; + displacement: (id: string) => number; + name: (id: string) => string; + }; + Plane: { + requiresLicense: (id: string) => boolean; + maxGroundSpeed: (id: string) => number; + maxTakeoffWeight: (id: string) => number; + maxCruisingAltitude: (id: string) => number; + name: (id: string) => string; + } +} +export type NoTypeParamBoatRequired = ReturnType; +type TypeHardcodedAsParameterWithoutReturnType = DataFetchFns[T][F]; +export type allAreFunctionsAsExpected = TypeHardcodedAsParameterWithoutReturnType<'Boat', keyof DataFetchFns['Boat']>; +export type returnTypeOfFunctions = ReturnType; //string | number | boolean as expected +export type SucceedingCombo = ReturnType>; +export type FailingCombo = ReturnType>; +export type TypeHardcodedAsParameter = ReturnType; +type VehicleSelector = DataFetchFns[T]; +export type TypeHardcodedAsParameter2 = ReturnType[F]>; +export type TypeGeneric = ReturnType; + + +//// [constraintWithIndexedAccess.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/tests/baselines/reference/constraintWithIndexedAccess.symbols b/tests/baselines/reference/constraintWithIndexedAccess.symbols new file mode 100644 index 0000000000000..18a18caa5edab --- /dev/null +++ b/tests/baselines/reference/constraintWithIndexedAccess.symbols @@ -0,0 +1,139 @@ +=== tests/cases/compiler/constraintWithIndexedAccess.ts === +// #52399 +type DataFetchFns = { +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) + + Boat: { +>Boat : Symbol(Boat, Decl(constraintWithIndexedAccess.ts, 1, 21)) + + requiresLicense: (id: string) => boolean; +>requiresLicense : Symbol(requiresLicense, Decl(constraintWithIndexedAccess.ts, 2, 11)) +>id : Symbol(id, Decl(constraintWithIndexedAccess.ts, 3, 26)) + + maxGroundSpeed: (id: string) => number; +>maxGroundSpeed : Symbol(maxGroundSpeed, Decl(constraintWithIndexedAccess.ts, 3, 49)) +>id : Symbol(id, Decl(constraintWithIndexedAccess.ts, 4, 25)) + + description: (id: string) => string; +>description : Symbol(description, Decl(constraintWithIndexedAccess.ts, 4, 47)) +>id : Symbol(id, Decl(constraintWithIndexedAccess.ts, 5, 22)) + + displacement: (id: string) => number; +>displacement : Symbol(displacement, Decl(constraintWithIndexedAccess.ts, 5, 44)) +>id : Symbol(id, Decl(constraintWithIndexedAccess.ts, 6, 23)) + + name: (id: string) => string; +>name : Symbol(name, Decl(constraintWithIndexedAccess.ts, 6, 45)) +>id : Symbol(id, Decl(constraintWithIndexedAccess.ts, 7, 15)) + + }; + Plane: { +>Plane : Symbol(Plane, Decl(constraintWithIndexedAccess.ts, 8, 6)) + + requiresLicense: (id: string) => boolean; +>requiresLicense : Symbol(requiresLicense, Decl(constraintWithIndexedAccess.ts, 9, 12)) +>id : Symbol(id, Decl(constraintWithIndexedAccess.ts, 10, 26)) + + maxGroundSpeed: (id: string) => number; +>maxGroundSpeed : Symbol(maxGroundSpeed, Decl(constraintWithIndexedAccess.ts, 10, 49)) +>id : Symbol(id, Decl(constraintWithIndexedAccess.ts, 11, 25)) + + maxTakeoffWeight: (id: string) => number; +>maxTakeoffWeight : Symbol(maxTakeoffWeight, Decl(constraintWithIndexedAccess.ts, 11, 47)) +>id : Symbol(id, Decl(constraintWithIndexedAccess.ts, 12, 27)) + + maxCruisingAltitude: (id: string) => number; +>maxCruisingAltitude : Symbol(maxCruisingAltitude, Decl(constraintWithIndexedAccess.ts, 12, 49)) +>id : Symbol(id, Decl(constraintWithIndexedAccess.ts, 13, 30)) + + name: (id: string) => string; +>name : Symbol(name, Decl(constraintWithIndexedAccess.ts, 13, 52)) +>id : Symbol(id, Decl(constraintWithIndexedAccess.ts, 14, 15)) + } +} +export type NoTypeParamBoatRequired = ReturnType; +>NoTypeParamBoatRequired : Symbol(NoTypeParamBoatRequired, Decl(constraintWithIndexedAccess.ts, 16, 1)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 17, 36)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 17, 36)) + +type TypeHardcodedAsParameterWithoutReturnType = DataFetchFns[T][F]; +>TypeHardcodedAsParameterWithoutReturnType : Symbol(TypeHardcodedAsParameterWithoutReturnType, Decl(constraintWithIndexedAccess.ts, 17, 112)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 18, 47)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 18, 64)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 18, 47)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 18, 47)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 18, 64)) + +export type allAreFunctionsAsExpected = TypeHardcodedAsParameterWithoutReturnType<'Boat', keyof DataFetchFns['Boat']>; +>allAreFunctionsAsExpected : Symbol(allAreFunctionsAsExpected, Decl(constraintWithIndexedAccess.ts, 18, 119)) +>TypeHardcodedAsParameterWithoutReturnType : Symbol(TypeHardcodedAsParameterWithoutReturnType, Decl(constraintWithIndexedAccess.ts, 17, 112)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) + +export type returnTypeOfFunctions = ReturnType; //string | number | boolean as expected +>returnTypeOfFunctions : Symbol(returnTypeOfFunctions, Decl(constraintWithIndexedAccess.ts, 19, 118)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>allAreFunctionsAsExpected : Symbol(allAreFunctionsAsExpected, Decl(constraintWithIndexedAccess.ts, 18, 119)) + +export type SucceedingCombo = ReturnType>; +>SucceedingCombo : Symbol(SucceedingCombo, Decl(constraintWithIndexedAccess.ts, 20, 74)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>TypeHardcodedAsParameterWithoutReturnType : Symbol(TypeHardcodedAsParameterWithoutReturnType, Decl(constraintWithIndexedAccess.ts, 17, 112)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) + +export type FailingCombo = ReturnType>; +>FailingCombo : Symbol(FailingCombo, Decl(constraintWithIndexedAccess.ts, 21, 120)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 22, 25)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 22, 42)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 22, 25)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>TypeHardcodedAsParameterWithoutReturnType : Symbol(TypeHardcodedAsParameterWithoutReturnType, Decl(constraintWithIndexedAccess.ts, 17, 112)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 22, 25)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 22, 42)) + +export type TypeHardcodedAsParameter = ReturnType; +>TypeHardcodedAsParameter : Symbol(TypeHardcodedAsParameter, Decl(constraintWithIndexedAccess.ts, 22, 137)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 23, 37)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 23, 54)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 23, 37)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 23, 37)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 23, 54)) + +type VehicleSelector = DataFetchFns[T]; +>VehicleSelector : Symbol(VehicleSelector, Decl(constraintWithIndexedAccess.ts, 23, 121)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 24, 21)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 24, 21)) + +export type TypeHardcodedAsParameter2 = ReturnType[F]>; +>TypeHardcodedAsParameter2 : Symbol(TypeHardcodedAsParameter2, Decl(constraintWithIndexedAccess.ts, 24, 69)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 25, 38)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 25, 55)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 25, 38)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>VehicleSelector : Symbol(VehicleSelector, Decl(constraintWithIndexedAccess.ts, 23, 121)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 25, 38)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 25, 55)) + +export type TypeGeneric = ReturnType; +>TypeGeneric : Symbol(TypeGeneric, Decl(constraintWithIndexedAccess.ts, 25, 125)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 26, 24)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 26, 53)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 26, 24)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 26, 24)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 26, 53)) + diff --git a/tests/baselines/reference/constraintWithIndexedAccess.types b/tests/baselines/reference/constraintWithIndexedAccess.types new file mode 100644 index 0000000000000..da301001cb6dc --- /dev/null +++ b/tests/baselines/reference/constraintWithIndexedAccess.types @@ -0,0 +1,83 @@ +=== tests/cases/compiler/constraintWithIndexedAccess.ts === +// #52399 +type DataFetchFns = { +>DataFetchFns : { Boat: { requiresLicense: (id: string) => boolean; maxGroundSpeed: (id: string) => number; description: (id: string) => string; displacement: (id: string) => number; name: (id: string) => string; }; Plane: { requiresLicense: (id: string) => boolean; maxGroundSpeed: (id: string) => number; maxTakeoffWeight: (id: string) => number; maxCruisingAltitude: (id: string) => number; name: (id: string) => string; }; } + + Boat: { +>Boat : { requiresLicense: (id: string) => boolean; maxGroundSpeed: (id: string) => number; description: (id: string) => string; displacement: (id: string) => number; name: (id: string) => string; } + + requiresLicense: (id: string) => boolean; +>requiresLicense : (id: string) => boolean +>id : string + + maxGroundSpeed: (id: string) => number; +>maxGroundSpeed : (id: string) => number +>id : string + + description: (id: string) => string; +>description : (id: string) => string +>id : string + + displacement: (id: string) => number; +>displacement : (id: string) => number +>id : string + + name: (id: string) => string; +>name : (id: string) => string +>id : string + + }; + Plane: { +>Plane : { requiresLicense: (id: string) => boolean; maxGroundSpeed: (id: string) => number; maxTakeoffWeight: (id: string) => number; maxCruisingAltitude: (id: string) => number; name: (id: string) => string; } + + requiresLicense: (id: string) => boolean; +>requiresLicense : (id: string) => boolean +>id : string + + maxGroundSpeed: (id: string) => number; +>maxGroundSpeed : (id: string) => number +>id : string + + maxTakeoffWeight: (id: string) => number; +>maxTakeoffWeight : (id: string) => number +>id : string + + maxCruisingAltitude: (id: string) => number; +>maxCruisingAltitude : (id: string) => number +>id : string + + name: (id: string) => string; +>name : (id: string) => string +>id : string + } +} +export type NoTypeParamBoatRequired = ReturnType; +>NoTypeParamBoatRequired : NoTypeParamBoatRequired + +type TypeHardcodedAsParameterWithoutReturnType = DataFetchFns[T][F]; +>TypeHardcodedAsParameterWithoutReturnType : TypeHardcodedAsParameterWithoutReturnType + +export type allAreFunctionsAsExpected = TypeHardcodedAsParameterWithoutReturnType<'Boat', keyof DataFetchFns['Boat']>; +>allAreFunctionsAsExpected : ((id: string) => boolean) | ((id: string) => number) | ((id: string) => string) | ((id: string) => number) | ((id: string) => string) + +export type returnTypeOfFunctions = ReturnType; //string | number | boolean as expected +>returnTypeOfFunctions : string | number | boolean + +export type SucceedingCombo = ReturnType>; +>SucceedingCombo : string | number | boolean + +export type FailingCombo = ReturnType>; +>FailingCombo : FailingCombo + +export type TypeHardcodedAsParameter = ReturnType; +>TypeHardcodedAsParameter : TypeHardcodedAsParameter + +type VehicleSelector = DataFetchFns[T]; +>VehicleSelector : VehicleSelector + +export type TypeHardcodedAsParameter2 = ReturnType[F]>; +>TypeHardcodedAsParameter2 : TypeHardcodedAsParameter2 + +export type TypeGeneric = ReturnType; +>TypeGeneric : TypeGeneric + diff --git a/tests/baselines/reference/deepComparisons.errors.txt b/tests/baselines/reference/deepComparisons.errors.txt index 663d5d80d1b9f..a86552a760c2a 100644 --- a/tests/baselines/reference/deepComparisons.errors.txt +++ b/tests/baselines/reference/deepComparisons.errors.txt @@ -1,15 +1,12 @@ tests/cases/compiler/deepComparisons.ts(2,9): error TS2322: Type 'T' is not assignable to type 'Extract'. tests/cases/compiler/deepComparisons.ts(3,9): error TS2322: Type 'T[K1]' is not assignable to type 'Extract'. - Type 'T[keyof T]' is not assignable to type 'Extract'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'Extract'. - Type 'T[string]' is not assignable to type 'Extract'. + Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'Extract'. + Type 'T[string]' is not assignable to type 'Extract'. tests/cases/compiler/deepComparisons.ts(4,9): error TS2322: Type 'T[K1][K2]' is not assignable to type 'Extract'. - Type 'T[K1][keyof T[K1]]' is not assignable to type 'Extract'. - Type 'T[K1][string] | T[K1][number] | T[K1][symbol]' is not assignable to type 'Extract'. - Type 'T[K1][string]' is not assignable to type 'Extract'. - Type 'T[keyof T][string]' is not assignable to type 'Extract'. - Type 'T[string][string] | T[number][string] | T[symbol][string]' is not assignable to type 'Extract'. - Type 'T[string][string]' is not assignable to type 'Extract'. + Type 'T[K1][string] | T[K1][number] | T[K1][symbol]' is not assignable to type 'Extract'. + Type 'T[K1][string]' is not assignable to type 'Extract'. + Type 'T[string][string] | T[number][string] | T[symbol][string]' is not assignable to type 'Extract'. + Type 'T[string][string]' is not assignable to type 'Extract'. ==== tests/cases/compiler/deepComparisons.ts (3 errors) ==== @@ -20,18 +17,15 @@ tests/cases/compiler/deepComparisons.ts(4,9): error TS2322: Type 'T[K1][K2]' is let v2: Extract = 0 as any as T[K1]; // Error ~~ !!! error TS2322: Type 'T[K1]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'Extract'. let v3: Extract = 0 as any as T[K1][K2]; // No error ~~ !!! error TS2322: Type 'T[K1][K2]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[K1][keyof T[K1]]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[K1][string] | T[K1][number] | T[K1][symbol]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[K1][string]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[keyof T][string]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[string][string] | T[number][string] | T[symbol][string]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[string][string]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[K1][string] | T[K1][number] | T[K1][symbol]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[K1][string]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[string][string] | T[number][string] | T[symbol][string]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[string][string]' is not assignable to type 'Extract'. } type Foo = { x: Foo }; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.errors.txt b/tests/baselines/reference/keyofAndIndexedAccess.errors.txt index cbad8ef2699e8..294fbcc7d6e99 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccess.errors.txt @@ -2,15 +2,15 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(205,24): error TS23 Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. Type 'T[string]' is not assignable to type 'object'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(211,24): error TS2322: Type 'T[K]' is not assignable to type 'object'. - Type 'T[keyof T]' is not assignable to type 'object'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. - Type 'T[string]' is not assignable to type 'object'. + Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. + Type 'T[string]' is not assignable to type 'object'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(316,5): error TS2322: Type 'T' is not assignable to type '{}'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(317,5): error TS2322: Type 'T[keyof T]' is not assignable to type '{}'. Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. Type 'T[string]' is not assignable to type '{}'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(318,5): error TS2322: Type 'T[K]' is not assignable to type '{}'. - Type 'T[keyof T]' is not assignable to type '{}'. + Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. + Type 'T[string]' is not assignable to type '{}'. ==== tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts (5 errors) ==== @@ -231,9 +231,8 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(318,5): error TS232 const b = "foo" in obj[key]; ~~~~~~~~ !!! error TS2322: Type 'T[K]' is not assignable to type 'object'. -!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'object'. -!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'object'. +!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'object'. } function f60(source: T, target: T) { @@ -350,7 +349,8 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(318,5): error TS232 a = z; ~ !!! error TS2322: Type 'T[K]' is not assignable to type '{}'. -!!! error TS2322: Type 'T[keyof T]' is not assignable to type '{}'. +!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. +!!! error TS2322: Type 'T[string]' is not assignable to type '{}'. } function f92(x: T, y: T[keyof T], z: T[K]) { diff --git a/tests/baselines/reference/mappedTypeRelationships.errors.txt b/tests/baselines/reference/mappedTypeRelationships.errors.txt index 1abc27cd24537..285c592965e9d 100644 --- a/tests/baselines/reference/mappedTypeRelationships.errors.txt +++ b/tests/baselines/reference/mappedTypeRelationships.errors.txt @@ -20,9 +20,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(41,5): error TS2 tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(45,5): error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'. 'T[K]' could be instantiated with an arbitrary type which could be unrelated to 'U[K] | undefined'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(46,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'. - Type 'T[keyof T]' is not assignable to type 'U[K] | undefined'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'U[K] | undefined'. - Type 'T[string]' is not assignable to type 'U[K] | undefined'. + Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'U[K] | undefined'. + Type 'T[string]' is not assignable to type 'U[K] | undefined'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(51,5): error TS2542: Index signature in type 'Readonly' only permits reading. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(56,5): error TS2542: Index signature in type 'Readonly' only permits reading. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(61,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. @@ -156,9 +155,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS y[k] = x[k]; // Error ~~~~ !!! error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'. -!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[K] | undefined'. -!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'U[K] | undefined'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K] | undefined'. +!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'U[K] | undefined'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K] | undefined'. } function f20(x: T, y: Readonly, k: keyof T) { diff --git a/tests/baselines/reference/mappedTypes6.errors.txt b/tests/baselines/reference/mappedTypes6.errors.txt index 965ee9f1f8b5a..19a7793f47bf5 100644 --- a/tests/baselines/reference/mappedTypes6.errors.txt +++ b/tests/baselines/reference/mappedTypes6.errors.txt @@ -4,23 +4,14 @@ tests/cases/conformance/types/mapped/mappedTypes6.ts(27,5): error TS2322: Type ' 'T' could be instantiated with an arbitrary type which could be unrelated to 'Partial'. tests/cases/conformance/types/mapped/mappedTypes6.ts(37,5): error TS2322: Type 'Required' is not assignable to type 'Denullified'. Type 'T[P]' is not assignable to type 'NonNullable'. - Type 'T[keyof T]' is not assignable to type 'NonNullable'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'NonNullable'. - Type 'T[string]' is not assignable to type 'NonNullable'. - Type 'T[string]' is not assignable to type 'T[P]'. - Type 'string' is not assignable to type 'P'. - 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. - Type 'T[keyof T]' is not assignable to type 'T[P]'. - Type 'keyof T' is not assignable to type 'P'. - 'keyof T' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. - Type 'string | number | symbol' is not assignable to type 'P'. - 'string | number | symbol' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. - Type 'string' is not assignable to type 'P'. - 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. - Type 'T[P]' is not assignable to type '{}'. - Type 'T[keyof T]' is not assignable to type '{}'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. - Type 'T[string]' is not assignable to type '{}'. + Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'NonNullable'. + Type 'T[string]' is not assignable to type 'NonNullable'. + Type 'T[string]' is not assignable to type 'T[P]'. + Type 'string' is not assignable to type 'P'. + 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. + Type 'T[P]' is not assignable to type '{}'. + Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. + Type 'T[string]' is not assignable to type '{}'. tests/cases/conformance/types/mapped/mappedTypes6.ts(38,5): error TS2322: Type 'T' is not assignable to type 'Denullified'. tests/cases/conformance/types/mapped/mappedTypes6.ts(39,5): error TS2322: Type 'Partial' is not assignable to type 'Denullified'. tests/cases/conformance/types/mapped/mappedTypes6.ts(42,5): error TS2322: Type 'T' is not assignable to type 'Required'. @@ -89,23 +80,14 @@ tests/cases/conformance/types/mapped/mappedTypes6.ts(120,4): error TS2540: Canno ~ !!! error TS2322: Type 'Required' is not assignable to type 'Denullified'. !!! error TS2322: Type 'T[P]' is not assignable to type 'NonNullable'. -!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'NonNullable'. -!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'NonNullable'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'NonNullable'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'T[P]'. -!!! error TS2322: Type 'string' is not assignable to type 'P'. -!!! error TS2322: 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. -!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'T[P]'. -!!! error TS2322: Type 'keyof T' is not assignable to type 'P'. -!!! error TS2322: 'keyof T' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. -!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'P'. -!!! error TS2322: 'string | number | symbol' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. -!!! error TS2322: Type 'string' is not assignable to type 'P'. -!!! error TS2322: 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. -!!! error TS2322: Type 'T[P]' is not assignable to type '{}'. -!!! error TS2322: Type 'T[keyof T]' is not assignable to type '{}'. -!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. -!!! error TS2322: Type 'T[string]' is not assignable to type '{}'. +!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'NonNullable'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'NonNullable'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'T[P]'. +!!! error TS2322: Type 'string' is not assignable to type 'P'. +!!! error TS2322: 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. +!!! error TS2322: Type 'T[P]' is not assignable to type '{}'. +!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. +!!! error TS2322: Type 'T[string]' is not assignable to type '{}'. w = y; // Error ~ !!! error TS2322: Type 'T' is not assignable to type 'Denullified'. diff --git a/tests/cases/compiler/constraintWithIndexedAccess.ts b/tests/cases/compiler/constraintWithIndexedAccess.ts new file mode 100644 index 0000000000000..d082e187e3fc3 --- /dev/null +++ b/tests/cases/compiler/constraintWithIndexedAccess.ts @@ -0,0 +1,27 @@ +// #52399 +type DataFetchFns = { + Boat: { + requiresLicense: (id: string) => boolean; + maxGroundSpeed: (id: string) => number; + description: (id: string) => string; + displacement: (id: string) => number; + name: (id: string) => string; + }; + Plane: { + requiresLicense: (id: string) => boolean; + maxGroundSpeed: (id: string) => number; + maxTakeoffWeight: (id: string) => number; + maxCruisingAltitude: (id: string) => number; + name: (id: string) => string; + } +} +export type NoTypeParamBoatRequired = ReturnType; +type TypeHardcodedAsParameterWithoutReturnType = DataFetchFns[T][F]; +export type allAreFunctionsAsExpected = TypeHardcodedAsParameterWithoutReturnType<'Boat', keyof DataFetchFns['Boat']>; +export type returnTypeOfFunctions = ReturnType; //string | number | boolean as expected +export type SucceedingCombo = ReturnType>; +export type FailingCombo = ReturnType>; +export type TypeHardcodedAsParameter = ReturnType; +type VehicleSelector = DataFetchFns[T]; +export type TypeHardcodedAsParameter2 = ReturnType[F]>; +export type TypeGeneric = ReturnType; From 3df8c50508999c9843cdd10a164993e04affe70f Mon Sep 17 00:00:00 2001 From: SHIMA RYUHEI <65934663+islandryu@users.noreply.github.com> Date: Sat, 18 Mar 2023 20:29:06 +0900 Subject: [PATCH 2/3] Changed processing for IndexAccess to be done in sourceFlags & TypeFlags.TypeVariable section --- src/compiler/checker.ts | 18 +++-- .../constraintWithIndexedAccess.errors.txt | 69 +++++++++++++++++++ .../reference/constraintWithIndexedAccess.js | 2 + .../constraintWithIndexedAccess.symbols | 24 +++++++ .../constraintWithIndexedAccess.types | 6 ++ .../reference/deepComparisons.errors.txt | 30 ++++---- .../keyofAndIndexedAccess.errors.txt | 16 ++--- .../mappedTypeRelationships.errors.txt | 10 +-- .../reference/mappedTypes6.errors.txt | 50 +++++++++----- .../compiler/constraintWithIndexedAccess.ts | 2 + 10 files changed, 181 insertions(+), 46 deletions(-) create mode 100644 tests/baselines/reference/constraintWithIndexedAccess.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f68718e8aabe5..448577553efda 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13508,12 +13508,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // we substitute an instantiation of E where P is replaced with X. return substituteIndexedMappedType(type.objectType as MappedType, type.indexType); } - const indexType = type.indexType; - let indexConstraint = getSimplifiedTypeOrConstraint(indexType); - if (indexConstraint && indexConstraint.flags & TypeFlags.Index) { - const constraint = getBaseConstraintOfType((indexConstraint as IndexType).type); - indexConstraint = constraint && constraint !== noConstraintType ? getIndexType(constraint) : keyofConstraintType; - } + const indexConstraint = getSimplifiedTypeOrConstraint(type.indexType); if (indexConstraint && indexConstraint !== type.indexType) { const indexedAccess = getIndexedAccessTypeOrUndefined(type.objectType, indexConstraint, type.accessFlags); if (indexedAccess) { @@ -21471,6 +21466,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, RecursionFlags.Source, reportErrors && constraint !== unknownType && !(targetFlags & sourceFlags & TypeFlags.TypeParameter), /*headMessage*/ undefined, intersectionState)) { return result; } + if (sourceFlags & TypeFlags.IndexedAccess) { + const indexType = (source as IndexedAccessType).indexType; + if (indexType.flags & TypeFlags.Index) { + const a = getBaseConstraintOfType((indexType as IndexType).type); + const indexConstraint = a && a !== noConstraintType ? getIndexType(a) : keyofConstraintType; + const constraint = getIndexedAccessType((source as IndexedAccessType).objectType, indexConstraint); + if (result = isRelatedTo(constraint, target, RecursionFlags.Source, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) { + return result; + } + } + } if (isMappedTypeGenericIndexedAccess(source)) { // For an indexed access type { [P in K]: E}[X], above we have already explored an instantiation of E with X // substituted for P. We also want to explore type { [P in K]: E }[C], where C is the constraint of X. diff --git a/tests/baselines/reference/constraintWithIndexedAccess.errors.txt b/tests/baselines/reference/constraintWithIndexedAccess.errors.txt new file mode 100644 index 0000000000000..7f87f96c16a95 --- /dev/null +++ b/tests/baselines/reference/constraintWithIndexedAccess.errors.txt @@ -0,0 +1,69 @@ +tests/cases/compiler/constraintWithIndexedAccess.ts(27,13): error TS2300: Duplicate identifier 'TypeGeneric'. +tests/cases/compiler/constraintWithIndexedAccess.ts(28,13): error TS2300: Duplicate identifier 'TypeGeneric'. +tests/cases/compiler/constraintWithIndexedAccess.ts(28,101): error TS2344: Type 'DataFetchFns[T][T]' does not satisfy the constraint '(...args: any) => any'. + Type 'DataFetchFns[T]["Boat"] | DataFetchFns[T]["Plane"]' is not assignable to type '(...args: any) => any'. + Type 'DataFetchFns[T]["Boat"]' is not assignable to type '(...args: any) => any'. +tests/cases/compiler/constraintWithIndexedAccess.ts(28,101): error TS2536: Type 'T' cannot be used to index type 'DataFetchFns[T]'. +tests/cases/compiler/constraintWithIndexedAccess.ts(29,13): error TS2300: Duplicate identifier 'TypeGeneric'. +tests/cases/compiler/constraintWithIndexedAccess.ts(29,101): error TS2536: Type 'F' cannot be used to index type 'DataFetchFns'. +tests/cases/compiler/constraintWithIndexedAccess.ts(29,101): error TS2344: Type 'DataFetchFns[F][F]' does not satisfy the constraint '(...args: any) => any'. + Type 'DataFetchFns[F][keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'. + Type 'DataFetchFns[F][string] | DataFetchFns[F][number] | DataFetchFns[F][symbol]' is not assignable to type '(...args: any) => any'. + Type 'DataFetchFns[F][string]' is not assignable to type '(...args: any) => any'. + Type 'DataFetchFns[keyof DataFetchFns[T]][string]' is not assignable to type '(...args: any) => any'. +tests/cases/compiler/constraintWithIndexedAccess.ts(29,101): error TS2536: Type 'F' cannot be used to index type 'DataFetchFns[F]'. + + +==== tests/cases/compiler/constraintWithIndexedAccess.ts (8 errors) ==== + // #52399 + type DataFetchFns = { + Boat: { + requiresLicense: (id: string) => boolean; + maxGroundSpeed: (id: string) => number; + description: (id: string) => string; + displacement: (id: string) => number; + name: (id: string) => string; + }; + Plane: { + requiresLicense: (id: string) => boolean; + maxGroundSpeed: (id: string) => number; + maxTakeoffWeight: (id: string) => number; + maxCruisingAltitude: (id: string) => number; + name: (id: string) => string; + } + } + export type NoTypeParamBoatRequired = ReturnType; + type TypeHardcodedAsParameterWithoutReturnType = DataFetchFns[T][F]; + export type allAreFunctionsAsExpected = TypeHardcodedAsParameterWithoutReturnType<'Boat', keyof DataFetchFns['Boat']>; + export type returnTypeOfFunctions = ReturnType; //string | number | boolean as expected + export type SucceedingCombo = ReturnType>; + export type FailingCombo = ReturnType>; + export type TypeHardcodedAsParameter = ReturnType; + type VehicleSelector = DataFetchFns[T]; + export type TypeHardcodedAsParameter2 = ReturnType[F]>; + export type TypeGeneric = ReturnType; + ~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'TypeGeneric'. + export type TypeGeneric = ReturnType; // error + ~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'TypeGeneric'. + ~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type 'DataFetchFns[T][T]' does not satisfy the constraint '(...args: any) => any'. +!!! error TS2344: Type 'DataFetchFns[T]["Boat"] | DataFetchFns[T]["Plane"]' is not assignable to type '(...args: any) => any'. +!!! error TS2344: Type 'DataFetchFns[T]["Boat"]' is not assignable to type '(...args: any) => any'. + ~~~~~~~~~~~~~~~~~~ +!!! error TS2536: Type 'T' cannot be used to index type 'DataFetchFns[T]'. + export type TypeGeneric = ReturnType; // error + ~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'TypeGeneric'. + ~~~~~~~~~~~~~~~ +!!! error TS2536: Type 'F' cannot be used to index type 'DataFetchFns'. + ~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type 'DataFetchFns[F][F]' does not satisfy the constraint '(...args: any) => any'. +!!! error TS2344: Type 'DataFetchFns[F][keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'. +!!! error TS2344: Type 'DataFetchFns[F][string] | DataFetchFns[F][number] | DataFetchFns[F][symbol]' is not assignable to type '(...args: any) => any'. +!!! error TS2344: Type 'DataFetchFns[F][string]' is not assignable to type '(...args: any) => any'. +!!! error TS2344: Type 'DataFetchFns[keyof DataFetchFns[T]][string]' is not assignable to type '(...args: any) => any'. + ~~~~~~~~~~~~~~~~~~ +!!! error TS2536: Type 'F' cannot be used to index type 'DataFetchFns[F]'. + \ No newline at end of file diff --git a/tests/baselines/reference/constraintWithIndexedAccess.js b/tests/baselines/reference/constraintWithIndexedAccess.js index a1e779f79667d..909ed24ad8a29 100644 --- a/tests/baselines/reference/constraintWithIndexedAccess.js +++ b/tests/baselines/reference/constraintWithIndexedAccess.js @@ -26,6 +26,8 @@ export type TypeHardcodedAsParameter = DataFetchFns[T]; export type TypeHardcodedAsParameter2 = ReturnType[F]>; export type TypeGeneric = ReturnType; +export type TypeGeneric = ReturnType; // error +export type TypeGeneric = ReturnType; // error //// [constraintWithIndexedAccess.js] diff --git a/tests/baselines/reference/constraintWithIndexedAccess.symbols b/tests/baselines/reference/constraintWithIndexedAccess.symbols index 18a18caa5edab..0b64cec616af0 100644 --- a/tests/baselines/reference/constraintWithIndexedAccess.symbols +++ b/tests/baselines/reference/constraintWithIndexedAccess.symbols @@ -137,3 +137,27 @@ export type TypeGenericT : Symbol(T, Decl(constraintWithIndexedAccess.ts, 26, 24)) >F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 26, 53)) +export type TypeGeneric = ReturnType; // error +>TypeGeneric : Symbol(TypeGeneric, Decl(constraintWithIndexedAccess.ts, 26, 120)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 27, 24)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 27, 53)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 27, 24)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 27, 24)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 27, 24)) + +export type TypeGeneric = ReturnType; // error +>TypeGeneric : Symbol(TypeGeneric, Decl(constraintWithIndexedAccess.ts, 27, 120)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 28, 24)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 28, 53)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 28, 24)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 28, 53)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 28, 53)) + diff --git a/tests/baselines/reference/constraintWithIndexedAccess.types b/tests/baselines/reference/constraintWithIndexedAccess.types index da301001cb6dc..4b67b5fc68ee8 100644 --- a/tests/baselines/reference/constraintWithIndexedAccess.types +++ b/tests/baselines/reference/constraintWithIndexedAccess.types @@ -81,3 +81,9 @@ export type TypeHardcodedAsParameter2 = ReturnType; >TypeGeneric : TypeGeneric +export type TypeGeneric = ReturnType; // error +>TypeGeneric : import("tests/cases/compiler/constraintWithIndexedAccess").TypeGeneric + +export type TypeGeneric = ReturnType; // error +>TypeGeneric : import("tests/cases/compiler/constraintWithIndexedAccess").TypeGeneric + diff --git a/tests/baselines/reference/deepComparisons.errors.txt b/tests/baselines/reference/deepComparisons.errors.txt index a86552a760c2a..663d5d80d1b9f 100644 --- a/tests/baselines/reference/deepComparisons.errors.txt +++ b/tests/baselines/reference/deepComparisons.errors.txt @@ -1,12 +1,15 @@ tests/cases/compiler/deepComparisons.ts(2,9): error TS2322: Type 'T' is not assignable to type 'Extract'. tests/cases/compiler/deepComparisons.ts(3,9): error TS2322: Type 'T[K1]' is not assignable to type 'Extract'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'Extract'. - Type 'T[string]' is not assignable to type 'Extract'. + Type 'T[keyof T]' is not assignable to type 'Extract'. + Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'Extract'. + Type 'T[string]' is not assignable to type 'Extract'. tests/cases/compiler/deepComparisons.ts(4,9): error TS2322: Type 'T[K1][K2]' is not assignable to type 'Extract'. - Type 'T[K1][string] | T[K1][number] | T[K1][symbol]' is not assignable to type 'Extract'. - Type 'T[K1][string]' is not assignable to type 'Extract'. - Type 'T[string][string] | T[number][string] | T[symbol][string]' is not assignable to type 'Extract'. - Type 'T[string][string]' is not assignable to type 'Extract'. + Type 'T[K1][keyof T[K1]]' is not assignable to type 'Extract'. + Type 'T[K1][string] | T[K1][number] | T[K1][symbol]' is not assignable to type 'Extract'. + Type 'T[K1][string]' is not assignable to type 'Extract'. + Type 'T[keyof T][string]' is not assignable to type 'Extract'. + Type 'T[string][string] | T[number][string] | T[symbol][string]' is not assignable to type 'Extract'. + Type 'T[string][string]' is not assignable to type 'Extract'. ==== tests/cases/compiler/deepComparisons.ts (3 errors) ==== @@ -17,15 +20,18 @@ tests/cases/compiler/deepComparisons.ts(4,9): error TS2322: Type 'T[K1][K2]' is let v2: Extract = 0 as any as T[K1]; // Error ~~ !!! error TS2322: Type 'T[K1]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'Extract'. let v3: Extract = 0 as any as T[K1][K2]; // No error ~~ !!! error TS2322: Type 'T[K1][K2]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[K1][string] | T[K1][number] | T[K1][symbol]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[K1][string]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[string][string] | T[number][string] | T[symbol][string]' is not assignable to type 'Extract'. -!!! error TS2322: Type 'T[string][string]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[K1][keyof T[K1]]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[K1][string] | T[K1][number] | T[K1][symbol]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[K1][string]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[keyof T][string]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[string][string] | T[number][string] | T[symbol][string]' is not assignable to type 'Extract'. +!!! error TS2322: Type 'T[string][string]' is not assignable to type 'Extract'. } type Foo = { x: Foo }; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.errors.txt b/tests/baselines/reference/keyofAndIndexedAccess.errors.txt index 294fbcc7d6e99..cbad8ef2699e8 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccess.errors.txt @@ -2,15 +2,15 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(205,24): error TS23 Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. Type 'T[string]' is not assignable to type 'object'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(211,24): error TS2322: Type 'T[K]' is not assignable to type 'object'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. - Type 'T[string]' is not assignable to type 'object'. + Type 'T[keyof T]' is not assignable to type 'object'. + Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. + Type 'T[string]' is not assignable to type 'object'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(316,5): error TS2322: Type 'T' is not assignable to type '{}'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(317,5): error TS2322: Type 'T[keyof T]' is not assignable to type '{}'. Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. Type 'T[string]' is not assignable to type '{}'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(318,5): error TS2322: Type 'T[K]' is not assignable to type '{}'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. - Type 'T[string]' is not assignable to type '{}'. + Type 'T[keyof T]' is not assignable to type '{}'. ==== tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts (5 errors) ==== @@ -231,8 +231,9 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(318,5): error TS232 const b = "foo" in obj[key]; ~~~~~~~~ !!! error TS2322: Type 'T[K]' is not assignable to type 'object'. -!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'object'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'object'. +!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'object'. } function f60(source: T, target: T) { @@ -349,8 +350,7 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(318,5): error TS232 a = z; ~ !!! error TS2322: Type 'T[K]' is not assignable to type '{}'. -!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. -!!! error TS2322: Type 'T[string]' is not assignable to type '{}'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type '{}'. } function f92(x: T, y: T[keyof T], z: T[K]) { diff --git a/tests/baselines/reference/mappedTypeRelationships.errors.txt b/tests/baselines/reference/mappedTypeRelationships.errors.txt index 285c592965e9d..1abc27cd24537 100644 --- a/tests/baselines/reference/mappedTypeRelationships.errors.txt +++ b/tests/baselines/reference/mappedTypeRelationships.errors.txt @@ -20,8 +20,9 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(41,5): error TS2 tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(45,5): error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'. 'T[K]' could be instantiated with an arbitrary type which could be unrelated to 'U[K] | undefined'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(46,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'U[K] | undefined'. - Type 'T[string]' is not assignable to type 'U[K] | undefined'. + Type 'T[keyof T]' is not assignable to type 'U[K] | undefined'. + Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'U[K] | undefined'. + Type 'T[string]' is not assignable to type 'U[K] | undefined'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(51,5): error TS2542: Index signature in type 'Readonly' only permits reading. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(56,5): error TS2542: Index signature in type 'Readonly' only permits reading. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(61,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. @@ -155,8 +156,9 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS y[k] = x[k]; // Error ~~~~ !!! error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'. -!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'U[K] | undefined'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K] | undefined'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[K] | undefined'. +!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'U[K] | undefined'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K] | undefined'. } function f20(x: T, y: Readonly, k: keyof T) { diff --git a/tests/baselines/reference/mappedTypes6.errors.txt b/tests/baselines/reference/mappedTypes6.errors.txt index 19a7793f47bf5..965ee9f1f8b5a 100644 --- a/tests/baselines/reference/mappedTypes6.errors.txt +++ b/tests/baselines/reference/mappedTypes6.errors.txt @@ -4,14 +4,23 @@ tests/cases/conformance/types/mapped/mappedTypes6.ts(27,5): error TS2322: Type ' 'T' could be instantiated with an arbitrary type which could be unrelated to 'Partial'. tests/cases/conformance/types/mapped/mappedTypes6.ts(37,5): error TS2322: Type 'Required' is not assignable to type 'Denullified'. Type 'T[P]' is not assignable to type 'NonNullable'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'NonNullable'. - Type 'T[string]' is not assignable to type 'NonNullable'. - Type 'T[string]' is not assignable to type 'T[P]'. - Type 'string' is not assignable to type 'P'. - 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. - Type 'T[P]' is not assignable to type '{}'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. - Type 'T[string]' is not assignable to type '{}'. + Type 'T[keyof T]' is not assignable to type 'NonNullable'. + Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'NonNullable'. + Type 'T[string]' is not assignable to type 'NonNullable'. + Type 'T[string]' is not assignable to type 'T[P]'. + Type 'string' is not assignable to type 'P'. + 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. + Type 'T[keyof T]' is not assignable to type 'T[P]'. + Type 'keyof T' is not assignable to type 'P'. + 'keyof T' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. + Type 'string | number | symbol' is not assignable to type 'P'. + 'string | number | symbol' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. + Type 'string' is not assignable to type 'P'. + 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. + Type 'T[P]' is not assignable to type '{}'. + Type 'T[keyof T]' is not assignable to type '{}'. + Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. + Type 'T[string]' is not assignable to type '{}'. tests/cases/conformance/types/mapped/mappedTypes6.ts(38,5): error TS2322: Type 'T' is not assignable to type 'Denullified'. tests/cases/conformance/types/mapped/mappedTypes6.ts(39,5): error TS2322: Type 'Partial' is not assignable to type 'Denullified'. tests/cases/conformance/types/mapped/mappedTypes6.ts(42,5): error TS2322: Type 'T' is not assignable to type 'Required'. @@ -80,14 +89,23 @@ tests/cases/conformance/types/mapped/mappedTypes6.ts(120,4): error TS2540: Canno ~ !!! error TS2322: Type 'Required' is not assignable to type 'Denullified'. !!! error TS2322: Type 'T[P]' is not assignable to type 'NonNullable'. -!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'NonNullable'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'NonNullable'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'T[P]'. -!!! error TS2322: Type 'string' is not assignable to type 'P'. -!!! error TS2322: 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. -!!! error TS2322: Type 'T[P]' is not assignable to type '{}'. -!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. -!!! error TS2322: Type 'T[string]' is not assignable to type '{}'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'NonNullable'. +!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'NonNullable'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'NonNullable'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'T[P]'. +!!! error TS2322: Type 'string' is not assignable to type 'P'. +!!! error TS2322: 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'T[P]'. +!!! error TS2322: Type 'keyof T' is not assignable to type 'P'. +!!! error TS2322: 'keyof T' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'P'. +!!! error TS2322: 'string | number | symbol' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. +!!! error TS2322: Type 'string' is not assignable to type 'P'. +!!! error TS2322: 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'. +!!! error TS2322: Type 'T[P]' is not assignable to type '{}'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type '{}'. +!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. +!!! error TS2322: Type 'T[string]' is not assignable to type '{}'. w = y; // Error ~ !!! error TS2322: Type 'T' is not assignable to type 'Denullified'. diff --git a/tests/cases/compiler/constraintWithIndexedAccess.ts b/tests/cases/compiler/constraintWithIndexedAccess.ts index d082e187e3fc3..67c8d7586d3cc 100644 --- a/tests/cases/compiler/constraintWithIndexedAccess.ts +++ b/tests/cases/compiler/constraintWithIndexedAccess.ts @@ -25,3 +25,5 @@ export type TypeHardcodedAsParameter = DataFetchFns[T]; export type TypeHardcodedAsParameter2 = ReturnType[F]>; export type TypeGeneric = ReturnType; +export type TypeGeneric = ReturnType; // error +export type TypeGeneric = ReturnType; // error From 845f5ab5919f7324130793f4105f3527b7af1a5a Mon Sep 17 00:00:00 2001 From: SHIMA RYUHEI <65934663+islandryu@users.noreply.github.com> Date: Sat, 18 Mar 2023 20:49:27 +0900 Subject: [PATCH 3/3] Minor corrections --- src/compiler/checker.ts | 4 +- .../constraintWithIndexedAccess.errors.txt | 37 +++++++--------- .../reference/constraintWithIndexedAccess.js | 6 +-- .../constraintWithIndexedAccess.symbols | 42 +++++++++---------- .../constraintWithIndexedAccess.types | 12 +++--- .../compiler/constraintWithIndexedAccess.ts | 6 +-- 6 files changed, 49 insertions(+), 58 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 448577553efda..2dc2675e3f828 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21469,8 +21469,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (sourceFlags & TypeFlags.IndexedAccess) { const indexType = (source as IndexedAccessType).indexType; if (indexType.flags & TypeFlags.Index) { - const a = getBaseConstraintOfType((indexType as IndexType).type); - const indexConstraint = a && a !== noConstraintType ? getIndexType(a) : keyofConstraintType; + const unresolvedIndexConstraint = getBaseConstraintOfType((indexType as IndexType).type); + const indexConstraint = unresolvedIndexConstraint && unresolvedIndexConstraint !== noConstraintType ? getIndexType(unresolvedIndexConstraint) : keyofConstraintType; const constraint = getIndexedAccessType((source as IndexedAccessType).objectType, indexConstraint); if (result = isRelatedTo(constraint, target, RecursionFlags.Source, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) { return result; diff --git a/tests/baselines/reference/constraintWithIndexedAccess.errors.txt b/tests/baselines/reference/constraintWithIndexedAccess.errors.txt index 7f87f96c16a95..f8a8539b9b29f 100644 --- a/tests/baselines/reference/constraintWithIndexedAccess.errors.txt +++ b/tests/baselines/reference/constraintWithIndexedAccess.errors.txt @@ -1,20 +1,17 @@ -tests/cases/compiler/constraintWithIndexedAccess.ts(27,13): error TS2300: Duplicate identifier 'TypeGeneric'. -tests/cases/compiler/constraintWithIndexedAccess.ts(28,13): error TS2300: Duplicate identifier 'TypeGeneric'. -tests/cases/compiler/constraintWithIndexedAccess.ts(28,101): error TS2344: Type 'DataFetchFns[T][T]' does not satisfy the constraint '(...args: any) => any'. +tests/cases/compiler/constraintWithIndexedAccess.ts(28,102): error TS2344: Type 'DataFetchFns[T][T]' does not satisfy the constraint '(...args: any) => any'. Type 'DataFetchFns[T]["Boat"] | DataFetchFns[T]["Plane"]' is not assignable to type '(...args: any) => any'. Type 'DataFetchFns[T]["Boat"]' is not assignable to type '(...args: any) => any'. -tests/cases/compiler/constraintWithIndexedAccess.ts(28,101): error TS2536: Type 'T' cannot be used to index type 'DataFetchFns[T]'. -tests/cases/compiler/constraintWithIndexedAccess.ts(29,13): error TS2300: Duplicate identifier 'TypeGeneric'. -tests/cases/compiler/constraintWithIndexedAccess.ts(29,101): error TS2536: Type 'F' cannot be used to index type 'DataFetchFns'. -tests/cases/compiler/constraintWithIndexedAccess.ts(29,101): error TS2344: Type 'DataFetchFns[F][F]' does not satisfy the constraint '(...args: any) => any'. +tests/cases/compiler/constraintWithIndexedAccess.ts(28,102): error TS2536: Type 'T' cannot be used to index type 'DataFetchFns[T]'. +tests/cases/compiler/constraintWithIndexedAccess.ts(29,102): error TS2536: Type 'F' cannot be used to index type 'DataFetchFns'. +tests/cases/compiler/constraintWithIndexedAccess.ts(29,102): error TS2344: Type 'DataFetchFns[F][F]' does not satisfy the constraint '(...args: any) => any'. Type 'DataFetchFns[F][keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'. Type 'DataFetchFns[F][string] | DataFetchFns[F][number] | DataFetchFns[F][symbol]' is not assignable to type '(...args: any) => any'. Type 'DataFetchFns[F][string]' is not assignable to type '(...args: any) => any'. Type 'DataFetchFns[keyof DataFetchFns[T]][string]' is not assignable to type '(...args: any) => any'. -tests/cases/compiler/constraintWithIndexedAccess.ts(29,101): error TS2536: Type 'F' cannot be used to index type 'DataFetchFns[F]'. +tests/cases/compiler/constraintWithIndexedAccess.ts(29,102): error TS2536: Type 'F' cannot be used to index type 'DataFetchFns[F]'. -==== tests/cases/compiler/constraintWithIndexedAccess.ts (8 errors) ==== +==== tests/cases/compiler/constraintWithIndexedAccess.ts (5 errors) ==== // #52399 type DataFetchFns = { Boat: { @@ -41,29 +38,23 @@ tests/cases/compiler/constraintWithIndexedAccess.ts(29,101): error TS2536: Type export type TypeHardcodedAsParameter = ReturnType; type VehicleSelector = DataFetchFns[T]; export type TypeHardcodedAsParameter2 = ReturnType[F]>; - export type TypeGeneric = ReturnType; - ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'TypeGeneric'. - export type TypeGeneric = ReturnType; // error - ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'TypeGeneric'. - ~~~~~~~~~~~~~~~~~~ + export type TypeGeneric1 = ReturnType; + export type TypeGeneric2 = ReturnType; // error + ~~~~~~~~~~~~~~~~~~ !!! error TS2344: Type 'DataFetchFns[T][T]' does not satisfy the constraint '(...args: any) => any'. !!! error TS2344: Type 'DataFetchFns[T]["Boat"] | DataFetchFns[T]["Plane"]' is not assignable to type '(...args: any) => any'. !!! error TS2344: Type 'DataFetchFns[T]["Boat"]' is not assignable to type '(...args: any) => any'. - ~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~ !!! error TS2536: Type 'T' cannot be used to index type 'DataFetchFns[T]'. - export type TypeGeneric = ReturnType; // error - ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'TypeGeneric'. - ~~~~~~~~~~~~~~~ + export type TypeGeneric3 = ReturnType; // error + ~~~~~~~~~~~~~~~ !!! error TS2536: Type 'F' cannot be used to index type 'DataFetchFns'. - ~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~ !!! error TS2344: Type 'DataFetchFns[F][F]' does not satisfy the constraint '(...args: any) => any'. !!! error TS2344: Type 'DataFetchFns[F][keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'. !!! error TS2344: Type 'DataFetchFns[F][string] | DataFetchFns[F][number] | DataFetchFns[F][symbol]' is not assignable to type '(...args: any) => any'. !!! error TS2344: Type 'DataFetchFns[F][string]' is not assignable to type '(...args: any) => any'. !!! error TS2344: Type 'DataFetchFns[keyof DataFetchFns[T]][string]' is not assignable to type '(...args: any) => any'. - ~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~ !!! error TS2536: Type 'F' cannot be used to index type 'DataFetchFns[F]'. \ No newline at end of file diff --git a/tests/baselines/reference/constraintWithIndexedAccess.js b/tests/baselines/reference/constraintWithIndexedAccess.js index 909ed24ad8a29..9a60445571e7b 100644 --- a/tests/baselines/reference/constraintWithIndexedAccess.js +++ b/tests/baselines/reference/constraintWithIndexedAccess.js @@ -25,9 +25,9 @@ export type FailingCombo = Re export type TypeHardcodedAsParameter = ReturnType; type VehicleSelector = DataFetchFns[T]; export type TypeHardcodedAsParameter2 = ReturnType[F]>; -export type TypeGeneric = ReturnType; -export type TypeGeneric = ReturnType; // error -export type TypeGeneric = ReturnType; // error +export type TypeGeneric1 = ReturnType; +export type TypeGeneric2 = ReturnType; // error +export type TypeGeneric3 = ReturnType; // error //// [constraintWithIndexedAccess.js] diff --git a/tests/baselines/reference/constraintWithIndexedAccess.symbols b/tests/baselines/reference/constraintWithIndexedAccess.symbols index 0b64cec616af0..60802dd468814 100644 --- a/tests/baselines/reference/constraintWithIndexedAccess.symbols +++ b/tests/baselines/reference/constraintWithIndexedAccess.symbols @@ -125,39 +125,39 @@ export type TypeHardcodedAsParameter2T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 25, 38)) >F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 25, 55)) -export type TypeGeneric = ReturnType; ->TypeGeneric : Symbol(TypeGeneric, Decl(constraintWithIndexedAccess.ts, 25, 125)) ->T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 26, 24)) +export type TypeGeneric1 = ReturnType; +>TypeGeneric1 : Symbol(TypeGeneric1, Decl(constraintWithIndexedAccess.ts, 25, 125)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 26, 25)) >DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) ->F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 26, 53)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 26, 54)) >DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) ->T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 26, 24)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 26, 25)) >ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) >DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) ->T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 26, 24)) ->F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 26, 53)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 26, 25)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 26, 54)) -export type TypeGeneric = ReturnType; // error ->TypeGeneric : Symbol(TypeGeneric, Decl(constraintWithIndexedAccess.ts, 26, 120)) ->T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 27, 24)) +export type TypeGeneric2 = ReturnType; // error +>TypeGeneric2 : Symbol(TypeGeneric2, Decl(constraintWithIndexedAccess.ts, 26, 121)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 27, 25)) >DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) ->F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 27, 53)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 27, 54)) >DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) ->T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 27, 24)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 27, 25)) >ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) >DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) ->T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 27, 24)) ->T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 27, 24)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 27, 25)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 27, 25)) -export type TypeGeneric = ReturnType; // error ->TypeGeneric : Symbol(TypeGeneric, Decl(constraintWithIndexedAccess.ts, 27, 120)) ->T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 28, 24)) +export type TypeGeneric3 = ReturnType; // error +>TypeGeneric3 : Symbol(TypeGeneric3, Decl(constraintWithIndexedAccess.ts, 27, 121)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 28, 25)) >DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) ->F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 28, 53)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 28, 54)) >DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) ->T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 28, 24)) +>T : Symbol(T, Decl(constraintWithIndexedAccess.ts, 28, 25)) >ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) >DataFetchFns : Symbol(DataFetchFns, Decl(constraintWithIndexedAccess.ts, 0, 0)) ->F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 28, 53)) ->F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 28, 53)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 28, 54)) +>F : Symbol(F, Decl(constraintWithIndexedAccess.ts, 28, 54)) diff --git a/tests/baselines/reference/constraintWithIndexedAccess.types b/tests/baselines/reference/constraintWithIndexedAccess.types index 4b67b5fc68ee8..0c236abe40453 100644 --- a/tests/baselines/reference/constraintWithIndexedAccess.types +++ b/tests/baselines/reference/constraintWithIndexedAccess.types @@ -78,12 +78,12 @@ type VehicleSelector = DataFetchFns[T]; export type TypeHardcodedAsParameter2 = ReturnType[F]>; >TypeHardcodedAsParameter2 : TypeHardcodedAsParameter2 -export type TypeGeneric = ReturnType; ->TypeGeneric : TypeGeneric +export type TypeGeneric1 = ReturnType; +>TypeGeneric1 : TypeGeneric1 -export type TypeGeneric = ReturnType; // error ->TypeGeneric : import("tests/cases/compiler/constraintWithIndexedAccess").TypeGeneric +export type TypeGeneric2 = ReturnType; // error +>TypeGeneric2 : TypeGeneric2 -export type TypeGeneric = ReturnType; // error ->TypeGeneric : import("tests/cases/compiler/constraintWithIndexedAccess").TypeGeneric +export type TypeGeneric3 = ReturnType; // error +>TypeGeneric3 : TypeGeneric3 diff --git a/tests/cases/compiler/constraintWithIndexedAccess.ts b/tests/cases/compiler/constraintWithIndexedAccess.ts index 67c8d7586d3cc..4b40399820c25 100644 --- a/tests/cases/compiler/constraintWithIndexedAccess.ts +++ b/tests/cases/compiler/constraintWithIndexedAccess.ts @@ -24,6 +24,6 @@ export type FailingCombo = Re export type TypeHardcodedAsParameter = ReturnType; type VehicleSelector = DataFetchFns[T]; export type TypeHardcodedAsParameter2 = ReturnType[F]>; -export type TypeGeneric = ReturnType; -export type TypeGeneric = ReturnType; // error -export type TypeGeneric = ReturnType; // error +export type TypeGeneric1 = ReturnType; +export type TypeGeneric2 = ReturnType; // error +export type TypeGeneric3 = ReturnType; // error