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

Typescript types from .d.ts file are not visible in the application

$
0
0

I was trying to type useContext hook and found this blog post https://blog.logrocket.com/how-to-use-react-context-with-typescript/as author wrote

  • The type.d.ts file that contains the TypeScript Types. The extension .d.ts allows using the types in other files without importing them

and the example shows usage like so:

const { saveTodo } = React.useContext(TodoContext) as ContextType

so I have created contexts.d.ts and inside I declared a type like so

import type { UserMetrics } from "../components";type UserMetricsContextType = {  userMetrics: UserMetrics;  setUserMetrics: React.Dispatch<React.SetStateAction<UserMetrics>>;};

and when I try to use it in the application, I get:

type UserMetricsContextType = /*unresolved*/ any

Could you please explain what am I doing wrong?

Thanks


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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