Skip to content

Defer processing of nested generic calls that return constructor types #54813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Defer processing of nested generic calls that return constructor types
  • Loading branch information
Andarist committed Jun 28, 2023
commit 8a8b22eacbdf181a54ba6dc615ceadc3fca34391
10 changes: 7 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33667,7 +33667,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// use the resolvingSignature singleton to indicate that we deferred processing. This result will be
// propagated out and eventually turned into silentNeverType (a type that is assignable to anything and
// from which we never make inferences).
if (checkMode & CheckMode.SkipGenericFunctions && !node.typeArguments && callSignatures.some(isGenericFunctionReturningFunction)) {
if (checkMode & CheckMode.SkipGenericFunctions && !node.typeArguments && callSignatures.some(isGenericFunctionReturningFunctionOrConstructor)) {
skippedGenericFunction(node, checkMode);
return resolvingSignature;
}
Expand All @@ -33680,8 +33680,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return resolveCall(node, callSignatures, candidatesOutArray, checkMode, callChainFlags);
}

function isGenericFunctionReturningFunction(signature: Signature) {
return !!(signature.typeParameters && isFunctionType(getReturnTypeOfSignature(signature)));
function isGenericFunctionReturningFunctionOrConstructor(signature: Signature) {
if (!signature.typeParameters) {
return false;
}
const returnType = getReturnTypeOfSignature(signature);
return isFunctionType(returnType) || isConstructorType(returnType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//// [tests/cases/compiler/inferenceGenericNestedCallReturningConstructor.ts] ////

=== inferenceGenericNestedCallReturningConstructor.ts ===
interface AssignObject<TContext> {
>AssignObject : Symbol(AssignObject, Decl(inferenceGenericNestedCallReturningConstructor.ts, 0, 0))
>TContext : Symbol(TContext, Decl(inferenceGenericNestedCallReturningConstructor.ts, 0, 23))

new (ctx: TContext): void;
>ctx : Symbol(ctx, Decl(inferenceGenericNestedCallReturningConstructor.ts, 1, 7))
>TContext : Symbol(TContext, Decl(inferenceGenericNestedCallReturningConstructor.ts, 0, 23))
}

declare function assign<TContext>(
>assign : Symbol(assign, Decl(inferenceGenericNestedCallReturningConstructor.ts, 2, 1))
>TContext : Symbol(TContext, Decl(inferenceGenericNestedCallReturningConstructor.ts, 4, 24))

assigner: (ctx: TContext) => void
>assigner : Symbol(assigner, Decl(inferenceGenericNestedCallReturningConstructor.ts, 4, 34))
>ctx : Symbol(ctx, Decl(inferenceGenericNestedCallReturningConstructor.ts, 5, 13))
>TContext : Symbol(TContext, Decl(inferenceGenericNestedCallReturningConstructor.ts, 4, 24))

): AssignObject<TContext>;
>AssignObject : Symbol(AssignObject, Decl(inferenceGenericNestedCallReturningConstructor.ts, 0, 0))
>TContext : Symbol(TContext, Decl(inferenceGenericNestedCallReturningConstructor.ts, 4, 24))

declare function createMachine<TContext>(config: {
>createMachine : Symbol(createMachine, Decl(inferenceGenericNestedCallReturningConstructor.ts, 6, 26))
>TContext : Symbol(TContext, Decl(inferenceGenericNestedCallReturningConstructor.ts, 8, 31))
>config : Symbol(config, Decl(inferenceGenericNestedCallReturningConstructor.ts, 8, 41))

context: TContext;
>context : Symbol(context, Decl(inferenceGenericNestedCallReturningConstructor.ts, 8, 50))
>TContext : Symbol(TContext, Decl(inferenceGenericNestedCallReturningConstructor.ts, 8, 31))

entry: AssignObject<TContext>;
>entry : Symbol(entry, Decl(inferenceGenericNestedCallReturningConstructor.ts, 9, 20))
>AssignObject : Symbol(AssignObject, Decl(inferenceGenericNestedCallReturningConstructor.ts, 0, 0))
>TContext : Symbol(TContext, Decl(inferenceGenericNestedCallReturningConstructor.ts, 8, 31))

}): void;

createMachine({
>createMachine : Symbol(createMachine, Decl(inferenceGenericNestedCallReturningConstructor.ts, 6, 26))

context: { count: 0 },
>context : Symbol(context, Decl(inferenceGenericNestedCallReturningConstructor.ts, 13, 15))
>count : Symbol(count, Decl(inferenceGenericNestedCallReturningConstructor.ts, 14, 12))

entry: assign((ctx) => {
>entry : Symbol(entry, Decl(inferenceGenericNestedCallReturningConstructor.ts, 14, 24))
>assign : Symbol(assign, Decl(inferenceGenericNestedCallReturningConstructor.ts, 2, 1))
>ctx : Symbol(ctx, Decl(inferenceGenericNestedCallReturningConstructor.ts, 15, 17))

ctx // { count: number }
>ctx : Symbol(ctx, Decl(inferenceGenericNestedCallReturningConstructor.ts, 15, 17))

}),
});

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//// [tests/cases/compiler/inferenceGenericNestedCallReturningConstructor.ts] ////

=== inferenceGenericNestedCallReturningConstructor.ts ===
interface AssignObject<TContext> {
new (ctx: TContext): void;
>ctx : TContext
}

declare function assign<TContext>(
>assign : <TContext>(assigner: (ctx: TContext) => void) => AssignObject<TContext>

assigner: (ctx: TContext) => void
>assigner : (ctx: TContext) => void
>ctx : TContext

): AssignObject<TContext>;

declare function createMachine<TContext>(config: {
>createMachine : <TContext>(config: { context: TContext; entry: AssignObject<TContext>;}) => void
>config : { context: TContext; entry: AssignObject<TContext>; }

context: TContext;
>context : TContext

entry: AssignObject<TContext>;
>entry : AssignObject<TContext>

}): void;

createMachine({
>createMachine({ context: { count: 0 }, entry: assign((ctx) => { ctx // { count: number } }),}) : void
>createMachine : <TContext>(config: { context: TContext; entry: AssignObject<TContext>; }) => void
>{ context: { count: 0 }, entry: assign((ctx) => { ctx // { count: number } }),} : { context: { count: number; }; entry: AssignObject<{ count: number; }>; }

context: { count: 0 },
>context : { count: number; }
>{ count: 0 } : { count: number; }
>count : number
>0 : 0

entry: assign((ctx) => {
>entry : AssignObject<{ count: number; }>
>assign((ctx) => { ctx // { count: number } }) : AssignObject<{ count: number; }>
>assign : <TContext>(assigner: (ctx: TContext) => void) => AssignObject<TContext>
>(ctx) => { ctx // { count: number } } : (ctx: { count: number; }) => void
>ctx : { count: number; }

ctx // { count: number }
>ctx : { count: number; }

}),
});

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @strict: true
// @noEmit: true

interface AssignObject<TContext> {
new (ctx: TContext): void;
}

declare function assign<TContext>(
assigner: (ctx: TContext) => void
): AssignObject<TContext>;

declare function createMachine<TContext>(config: {
context: TContext;
entry: AssignObject<TContext>;
}): void;

createMachine({
context: { count: 0 },
entry: assign((ctx) => {
ctx // { count: number }
}),
});
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy