Skip to content

Commit

Permalink
Cherry-pick PR #50797 into release-4.8 (#50798)
Browse files Browse the repository at this point in the history
Component commits:
23a1dd4 Fix bounds check

23784d7 Add regression test

Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
  • Loading branch information
TypeScript Bot and ahejlsberg authored Sep 16, 2022
1 parent bb8cf90 commit a3b3555
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35931,8 +35931,8 @@ namespace ts {
}

function getEffectiveTypeArgumentAtIndex(node: TypeReferenceNode | ExpressionWithTypeArguments, typeParameters: readonly TypeParameter[], index: number): Type {
if (index < typeParameters.length) {
return getTypeFromTypeNode(node.typeArguments![index]);
if (node.typeArguments && index < node.typeArguments.length) {
return getTypeFromTypeNode(node.typeArguments[index]);
}
return getEffectiveTypeArguments(node, typeParameters)[index];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,26 @@ type MyObject<T> = T extends ZodObject<infer U>
? U extends ZodRawShape
? U
: never
: never;
: never;

// Repro from #50479

type Cell<Value extends BaseValue = any, BaseValue = unknown> = {
id: string
}

type Items<Type extends Cell = Cell> = {
type: Type
name: string
}

type InferIOItemToJSType<T extends Items> =
T extends { type: infer U }
? U extends Cell<infer V/**, infer _ or unknown, or any valid type **/>
? V
: never
: never


//// [inferTypeConstraintInstantiationCircularity.js]
"use strict";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,51 @@ type MyObject<T> = T extends ZodObject<infer U>

: never
: never;

// Repro from #50479

type Cell<Value extends BaseValue = any, BaseValue = unknown> = {
>Cell : Symbol(Cell, Decl(inferTypeConstraintInstantiationCircularity.ts, 71, 10))
>Value : Symbol(Value, Decl(inferTypeConstraintInstantiationCircularity.ts, 75, 10))
>BaseValue : Symbol(BaseValue, Decl(inferTypeConstraintInstantiationCircularity.ts, 75, 40))
>BaseValue : Symbol(BaseValue, Decl(inferTypeConstraintInstantiationCircularity.ts, 75, 40))

id: string
>id : Symbol(id, Decl(inferTypeConstraintInstantiationCircularity.ts, 75, 65))
}

type Items<Type extends Cell = Cell> = {
>Items : Symbol(Items, Decl(inferTypeConstraintInstantiationCircularity.ts, 77, 1))
>Type : Symbol(Type, Decl(inferTypeConstraintInstantiationCircularity.ts, 79, 11))
>Cell : Symbol(Cell, Decl(inferTypeConstraintInstantiationCircularity.ts, 71, 10))
>Cell : Symbol(Cell, Decl(inferTypeConstraintInstantiationCircularity.ts, 71, 10))

type: Type
>type : Symbol(type, Decl(inferTypeConstraintInstantiationCircularity.ts, 79, 40))
>Type : Symbol(Type, Decl(inferTypeConstraintInstantiationCircularity.ts, 79, 11))

name: string
>name : Symbol(name, Decl(inferTypeConstraintInstantiationCircularity.ts, 80, 12))
}

type InferIOItemToJSType<T extends Items> =
>InferIOItemToJSType : Symbol(InferIOItemToJSType, Decl(inferTypeConstraintInstantiationCircularity.ts, 82, 1))
>T : Symbol(T, Decl(inferTypeConstraintInstantiationCircularity.ts, 84, 25))
>Items : Symbol(Items, Decl(inferTypeConstraintInstantiationCircularity.ts, 77, 1))

T extends { type: infer U }
>T : Symbol(T, Decl(inferTypeConstraintInstantiationCircularity.ts, 84, 25))
>type : Symbol(type, Decl(inferTypeConstraintInstantiationCircularity.ts, 85, 13))
>U : Symbol(U, Decl(inferTypeConstraintInstantiationCircularity.ts, 85, 25))

? U extends Cell<infer V/**, infer _ or unknown, or any valid type **/>
>U : Symbol(U, Decl(inferTypeConstraintInstantiationCircularity.ts, 85, 25))
>Cell : Symbol(Cell, Decl(inferTypeConstraintInstantiationCircularity.ts, 71, 10))
>V : Symbol(V, Decl(inferTypeConstraintInstantiationCircularity.ts, 86, 26))

? V
>V : Symbol(V, Decl(inferTypeConstraintInstantiationCircularity.ts, 86, 26))

: never
: never

Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,34 @@ type MyObject<T> = T extends ZodObject<infer U>
? U
: never
: never;

// Repro from #50479

type Cell<Value extends BaseValue = any, BaseValue = unknown> = {
>Cell : Cell<Value, BaseValue>

id: string
>id : string
}

type Items<Type extends Cell = Cell> = {
>Items : Items<Type>

type: Type
>type : Type

name: string
>name : string
}

type InferIOItemToJSType<T extends Items> =
>InferIOItemToJSType : InferIOItemToJSType<T>

T extends { type: infer U }
>type : U

? U extends Cell<infer V/**, infer _ or unknown, or any valid type **/>
? V
: never
: never

Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,22 @@ type MyObject<T> = T extends ZodObject<infer U>
? U extends ZodRawShape
? U
: never
: never;
: never;

// Repro from #50479

type Cell<Value extends BaseValue = any, BaseValue = unknown> = {
id: string
}

type Items<Type extends Cell = Cell> = {
type: Type
name: string
}

type InferIOItemToJSType<T extends Items> =
T extends { type: infer U }
? U extends Cell<infer V/**, infer _ or unknown, or any valid type **/>
? V
: never
: never

0 comments on commit a3b3555

Please sign in to comment.