Skip to content

Generics lost on currying for higher-order functions #440

@tgelu

Description

@tgelu

@tycho01 has closed #78 which was very related to this.

I have the following silly array map

let map = <A, B>(f: (x: A) => B, ar: Array<A>) : Array<B> =>{
  let next = ar.pop()
  return typeof next !== 'undefined' ? [f(next)].concat(map(f, ar)) : []
}

let cmap = curry(map)

This works just fine until I curry it. Then, no matter how I call it typescript won't compile it with the following error:

error TS2365: Operator '+' cannot be applied to types '{}' and '5'.
cmap(x => x + 5)([1, 2, 3])

Not even when I tell it that x is a number.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions