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

How to extend type from a library in TS?

$
0
0

I use a useTheme hook import { useTheme } from '@react-navigation/native' from react-navigation lib that returns colors object that is a type of Theme.

type Theme = {    dark: boolean;    colors: {        primary: string;        background: string;        card: string;        text: string;        border: string;        notification: string;    };};

In a file, where we have all layout/styles related stuff, I have extended it with one more property:

interface ITheme extends Theme {  colors: Theme['colors'] & {    textSecondary: string;  };}

How do i type cast it somehow it to a library type once, so the colors object that is returned from useTheme hook will become ITheme custom type anywhere i call this hook?
It gives me Property 'textSecondary' does not exist on type '{ primary: string; background: string; card: string; text: string; border: string; notification: string; }' error so far.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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