facebook / facebook/flow

Higher order generic function called on a generic function breaks generic inference

Aperta
#6,512 5 commenti 3 reazioni 0 assegnatari Vedi su GitHub
Typing: polymorphism
Lingua principale
Rust
Stelle
22.3k
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Here is a minimal bug representation. For me it is a surprise that `id(id)` returns a function of type `(T) => T` while just a bit more complex `idFn(id)` returns a function of type `empty => empty`. Sure, when the latter gets applied to an argument of a defined type it get's it's type inferred to, say, `number => number` in case of `f2(123)`. But this is not how you'd expect a second level generic to work. Or I'm missing something huge here? 😅

```js
function id(x: T): T {
return x
}

function idFn(x: A => B): A => B {
return x
}

// this works fine
const f1 = id(id)
f1(123).toFixed()
f1("123").concat()

// this looses it's generic nature :(
const f2 = idFn(id)
f2(123).toFixed()
f2("123").concat()
```

[flow.org/try](https://flow.org/try/#0GYVwdgxgLglg9mABDAJgHgCoD4AUAPALkQwEoiNEBvAKETsQCcBTKEBpPagX2utElgJkKAGJg0AQQA0iAEK5CiCYgC8WOWSWr1sqrXrNW7RJx7UA9OcRQAFjADOiAO5wGAa0fAYYJtQgJ7KERgAEZVYRxUEj4QnBCAJgBmEgA6KDgRGDwmFBxo0JwAIgTEwtT-SABDKDzeS2s7RwAbODh7JkcYKAByRwBzJh8GGAhEMGq2JkQCHD8AoOB48NQxSJR8+Lik1PTM7NyNopKylIqIatrqIA)

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.