question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript Definitions Missing

See original GitHub issue

Currently I can’t compile my typescript react project when trying to use the new styled-components/primitives library extension because typings definitions are not present for the react-primitives repository. There is also no @types/react-primitives present either.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
sullvncommented, Feb 13, 2018

As @mathieudutour suggested, you can import the types from @types/react-native.

I got it working by making a src/@types/react-primitives/index.d.ts file with the following contents:

declare module 'react-primitives' {
  export {
    StyleSheet,
    View,
    Text,
    Image,
    Touchable,
    Animated,
  } from 'react-native'
}

There will be one more step if you’re using React Primitives in a Webpack build. Webpack and React Native both declare global, incompatible type definitions for require.

So you’ll have add the following to your tsconfig.json to just avoid type-checking node_modules (which is faster anyways):

{
  "compilerOptions": {
    // Required for using `react-primitives` types, but
    // also makes typechecking faster in general.
    //
    // The problem actually stems from this project using
    // `@types/react-native` to fake types for `react-primitives`.
    // React Native and Webpack both define a global `require`
    // differently, so there's a conflict.
    "skipLibCheck": true,
  }
}

Hopefully that helps!

I would normally make a PR to this repo or DefinitelyTyped to just add these, but I’m not familiar enough with React Native and Primitives to know if it’s truly a one-to-one types match. Can someone more in-the-know help with that?

1reaction
brunolemoscommented, Aug 12, 2018

Someone posted a similar code from above on DefinitelyTyped so you can do this now: yarn add --dev @types/react-primitives.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to include missing type definition files in typescript ...
I would suggest switching to types from typeRoots and using an include pattern rather than files . { "compilerOptions": { "lib": ["dom" ...
Read more >
How to Declare Missing Types for External Libraries -- newline
Custom Types Declaration#. First, in your tsconfig.json add a directory path to type declarations:.
Read more >
Typescript: missing type definitions. · Issue #8642 - GitHub
I am opening this issue to report missing types when I notice that. Here is the first: Cookie options type does not have...
Read more >
Missing type definition (typescript) - Handsontable Forum
Hi, We have upgraded to the latest version (11.1.0) and are experiencing missing type definitions for the samplingRatio and ...
Read more >
How to add missing types to a library. : r/typescript - Reddit
I'm having trouble adding types to a library. The specific library itself is Shippo's node client. It comes with type definitions however ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found