Microsoft/TypeScript

Generic type inference failed

Open

#56 855 ouverte le 23 déc. 2023

Voir sur GitHub
 (4 commentaires) (0 réactions) (0 assignés)TypeScript (6 726 forks)batch import
BugDomain: check: Type InferenceHelp Wanted

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

Description

🔎 Search Terms

Generics

🕗 Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABKSAeAUIriAqBGAGk2xwGZEBTADygrABMBnRAb0QG0BrCgTwC5EjKACcYYAOYBdAQAoICWjQH4AlIgC8APkQA3ODHqIAvkWy4ALBtYnEAeluIAwnAC2LurAmI4IKIigAFjDMjBTQ8EhwwIjy9BSILgCG3MwwfgDucMKciAAOwnC5FMIANjwAdOiaMvSJUIkCLMRYOMp4ANzNiADSyuQAZLhBjDg8Raj4iINkmp1Gak1G6OgoEDJNZq2sXWYARvsCeABMpKZm2ImXMguIwhRQIMJIpC-txmdYJl292+fY+7s5ApqFAFjs-jEEIw4CUKOUSnBxECwIooOVLolripOhDzvIwNDYfDEcjUeUAdjwX9AsFyhB6dccRCvrj6WsbizsF95u0gA

💻 Code

function func<
    T1,
    T3 extends { [key: string]: (context: T1) => void },
    T4 = {}, // Commenting out this section of code makes it work properly.
>(data: {
    T: T1;
    K: T3 & ThisType<T1 & T3>;
}) {
}

func({
    T: {
        bbb: 123,
        aaa() { return 333; },
    },
    K: {
        bbb(context) {
            console.log(context.aaa());
            console.log(context.bbb);
            this.ccc();
        },
        ccc() { },
    },
});

🙁 Actual behavior

display an error message:

'context' is of type 'unknown'. 'context' is of type 'unknown'. 'T4' is declared but its value is never read. 'data' is declared but its value is never read.

🙂 Expected behavior

The type of 'context' should already be determined; it shouldn't be 'unknown'.

Additional information about the issue

No response

Guide contributeur