Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Type error when using generic function result as argument, but not when assigned to temp variable first #35339

Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixed
@fatcerberus

Description

@fatcerberus

Issue originally discovered by@eyelidlessness on Gitter.

TypeScript Version: 3.8.0-dev.20191123

Search Terms:genericreturntype

Code

declareconstfoo:<R1,F1extends()=>R1,R2,F2extends(input:ReturnType<F1>)=>R2>(f1:F1,f2:F2)=>anyconstf1=()=>({a:'a'})constf2=(input:{a:string})=>({b:'b'})foo(f1,f2)// GoodconstmakeF1=()=>f1;foo(makeF1(),f2)// GoodconstmakeF1p=<T>(t:T)=>f1;foo(makeF1p(''),f2// Error WHY :();constmade=makeF1p('');foo(made,// This is finef2)

Expected behavior:

Bothfoo() calls should compile as the only difference is whether the result of a function call is assigned to a temporary first.

Actual behavior:

The first call tofoo(), wheremakeF1p() is called inline, produces a type error at compile time. The second, where the return value ofmakeF1p() is assigned to temp variable first, compiles fine. The error is:

Argument of type '(input: { a: string; }) => { b: string; }' is not assignable to parameter of type '(input: unknown) => unknown'.  Types of parameters 'input' and 'input' are incompatible.    Type 'unknown' is not assignable to type '{ a: string; }'.

It almost seems like the type parameter inference machinery is leaking outside the scope of the call expression or something? It's weird, at any rate.

Playground Link:

https://www.typescriptlang.org/play/?ts=3.8.0-dev.20191123&ssl=1&ssc=1&pln=33&pc=1#code/CYUwxgNghgTiAEYD2A7AzgF3gMyUgXPADwBQ858ASgIwA0ZFAYtfCAB4YgrBrwAUASngBeAHxU6DcpQBM9CvEYzWHLj34BLFAAcArhkKUQGXTBQAVAJ7aQRZqKFiqMkqL5Sc1Qs3kVsM7xdHcSgUSxISZHQsbBZhfmD+AG94KEIAcih0+ABfAUjUTBxleL4tPQN4FLT4TBgtAHNcxL4UgCMMtuy8iNwkPljaYqEAehH4AHE8YAioooBbKABrEGYRBJFxWIBuXrw+RZXmQSH-UfGppBmC6PhD1eptdaJzN0rzRJ29-o975m0+Ol0gJfOR-PAxvAAKIwGBIGDwADqAAkAJrwfDuAS7G4LKCgdZ-R6A4E4vruBSLUBDSHmAAWGl4jJwWhAHn8JHyQA

Related Issues: I didn't find any, but@jack-williams says#30215 might be the root cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp