Skip to content

parameters: presume generics over any #14078

Closed

Description

TypeScript Version: any

Code

let identity = (x) => x; // degenerates to `(x: any) => any` instead of <T>(x: T) => T
let wrong: number = identity('foo'); // type-checks, while TS should have enough info to infer it's wrong

Expected behavior:
TS should be able to save parameter types (where unspecified) into generics so as to improve inference.

Actual behavior:
Things type-check while TS should have enough info to conclude they shouldn't.

Perhaps this could make for a compiler flag?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions