Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

TypeScript is seeing interface type but not deducing correctly

$
0
0

TypeScript compiler can't decide which type to use: or I don't understand what I'm doing.Am i doing something wrong with the type inference

type Func = (() => void) | ((id: number) => void);interface A {  [key: string]: (fn) => Func}interface B<G> {  [Property in keyof G]: Func}/* Example */const AObjects = {   addName: function addName(fn): Func {    return () => fn();  }  deletePerson: function deletePerson(fn): Func {    return (id) => fn(id);  }}function turnAtoB<A>(): B<A> {  ...Implementation details}// The buttons are using interface B functions<Button onPress={addName} /> // gives TypeScript Error -> deduces the types as ((id) => void) instead of (() => void)<Button onPress={() => deletePerson(id)} /> // correctly deduces the type as ((id) => void)

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>