Reputation: 81
I have a problem, already solved it, but make me confuse about modules.
I tried to import an Animated in my component.
import { Animated, Easing } from 'react-native';
and then, I tried to find Its type (flow), I found that answer in. Flow types for react-native's Animated library (Thank you).
import type AnimatedValue from 'react-native/Libraries/Animated/src/nodes/AnimatedValue';
The question is.
When I open Animated in import { Animated, Easing } from 'react-native';
(right click, then I go to type definition with "Visual code"), Why it doesn't go to Its module, but to this path? (Library/Caches)
I tried to find out this file (index.d.ts) in "react-native" modules, but I cant find it. Why?
Then I try to read index.d.ts, to find out type for Animated.Value.
export namespace Animated {
type AnimatedValue = Value;
type AnimatedValueXY = ValueXY;
export class Value extends AnimatedWithChildren {
Horraay, I got Animated.Value is a class, and Its type is an AnimatedValue. Then as usual to find Its path, I right click, then I go to type definition with "Visual code", but I found nothing.
So, how can this import type AnimatedValue from 'react-native/Libraries/Animated/src/nodes/AnimatedValue
relate to type AnimatedValue = Value;
in index.d.ts?
"react-native": "0.63.2",
Upvotes: 0
Views: 513
Reputation: 2503
index.d.ts
files are used to provide typescript type information about a module that's already written in JavaScript. This will allow you to use the javascript modules without the need to first convert them completely to ts
without getting any type error on your code.
Why it doesn't go to Its module, but to this path?
It's because when you install types for particular library using npm, they get installed under node_modules/@types/<library-name>/
location as index.d.ts
file. Therefore using VSCode's navigate to type definition feature takes you to this index.d.ts
file instead of taking you within library.
I tried to find out this file (index.d.ts) in "react-native" modules, but I cant find it. Why?
All index.d.ts
files are stored at node_modules/@types/<library-name>
not at node_modules/<library-name>
. As a result you can't finid these files in corresponding modules.
Upvotes: 1