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

Using useState hook with TypeScript

$
0
0

I wanted to know if I it's possible to use inheritance while setting the useState type. What I mean is if have an interface like that:

interface PackageItem {    id: number,    name: string,    address: string}

And another interface like that

interface Selectable {    selected: boolean}

Now I want to create a state where I will have an array of selectable packages,so I tried something like this:

const [selectablePackages, setSelectablePackages] = useState<(PackageItem extends Selectable)[]>();

But I keep getting an error, which highlights the extends word, saying:

Parsing error: Unexpected token, expected ","

I'm not setting the state type correctly, how can I achieve this?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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