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.

react-select/async and Typescript

See original GitHub issue

Hi!

I can’t seem to find a proper way to resolve this issue. When I try to import Async select I get a following TS error.

import SelectAsync from 'react-select/async';

Error:

Could not find a declaration file for module ‘react-select/async’. ‘<removed>/node_modules/react-select/async/dist/react-select.cjs.js’ implicitly has an ‘any’ type.ts(7016)

I found a couple of old threads online with the similar issue but none of the suggestions there could help. Any ideas how to resolve this?

Relevant packages from package.json:

"react-select": "^3.0.3",
"typescript": "^3.4.5",
"@types/react-select": "^2.0.19"

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:26
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

18reactions
Methuselah96commented, Jun 26, 2019
17reactions
justingrantcommented, Jun 11, 2019

@StanBright and others looking for a TS workaround, here’s what I did to solve this problem for react-select/creatable. You should be able to do something similar for react-select/async:

  1. Create a node_modules subfolder in my src folder. (not a typo-- put it inside your /src folder because you’ll want to check it into git!)
  2. Create a ./src/node_modules/react-select folder
  3. Create a ./src/node_modules/react-select/creatable folder
  4. Add a typings file in that folder: ./src/node_modules/react-select/creatable/index.d.ts and populate it with this content: EDIT: added one more line to handle non-default exports (thanks @dhruvio!)
import Creatable from 'react-select/lib/Creatable';
export * from 'react-select/lib/Creatable';
export default Creatable;

Doing this enables imports like this to work:

import Select from 'react-select/creatable';
import { Props as SelectProps } from 'react-select/creatable';

Once the 3.0 typings are populated in DefinitelyTyped, you should be able to remove this hack.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript - React Select
React Select. A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete, async and creatable support. Star25,561.
Read more >
react-select async loadOptions with TypeScript - Stack Overflow
I'm converting an existing react app to typescript, and I'm having trouble getting the react-select async loadOptions to parse correctly as ...
Read more >
React Ts React Select Async Paginate - StackBlitz
React + TypeScript starter project.
Read more >
TypeScript react-select cheat sheet - SaltyCrane
This is a list of TypeScript types for react-select generated from the ... react-select/async; react-select/base; react-select/creatable; react-select/v1 ...
Read more >
react-select-async-paginate - npm
Start using react-select-async-paginate in your project by ... TypeScript icon, indicating that this package has built-in type declarations.
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