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

Problems creating type definition for js library

$
0
0

I want to use a React Native/JavaScript library(without type declarations) in a TypeScript project, but then immediately run into a TS7016: Could not find a declaration file for module 'especific-library'error. So I create a declaration file with the name of the library that I wan to use like this:

react-native-backdrop.d.ts

declare module 'react-native-backdrop' {  function Backdrop(): JSX.Element;}

up to here everything is going great, in my typescript file, the problem disappears, now the problem is that when I try to use the component, I must pass some properties/arguments for it to work but, when I pass them ts throws the following error: Property 'some-property' does not exist on type 'IntrinsicAttributes'.

I think I should add the properties in the function I create in the d.ts file something like this:

import React from 'react';import {ColorValue} from 'react-native';declare module 'react-native-backdrop' {  function Backdrop(    visible?: boolean,    overlayColor?: ColorValue,    children?: React.ReactNode,  ): JSX.Element;}

but when I do this(add arguments/props) to my Backdrop function/component in react-native-backdrop.d.ts file, I get back the TS7016 error again in my ts file where I am implementing the library. Only when I leave the signature of the function without any parameter in d.ts file is that TS7016 error disappears, but it comes back and the error of the properties appears: Property 'some-property' does not exist on type 'IntrinsicAttributes'. in my function/component implementation.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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