Skip to content

inference strangeness - 3 #6037

Description

Overheard conversation on the street:

Q: Can I assign an array literal to a tuple in TypeScript?
A: Yes, sometimes you can.

letvalue : [string,string];value=['hey','nay'];// <-- works, an array literal can be assigned to a tuple functionfold<a,r>(values: a[],result: r,fold: (result: r,value: a)=>r) : r{for(letvalueofvalues){result=fold(result,value);}returnresult;}functionappend<a>(values: a[],value: a) : a[]{values.push(value);returnvalues;}fold([1,2,3],<[string,string][]>[],(result,value)=>append(// <-- doesn't work, an array literal is not assignable to tuple result,['','']));

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions