Generated .d.ts does not import destructure react imports
See original GitHub issueBug report
Below I have supplied a minimal repo. In our project we destructure react types in our files. The output of the bundle does not include these imports causing a malformed d.ts
Input code
import React, { ReactElement } from 'react';
export function Test(): ReactElement {
return <div />;
}
export const ForwardedRef = React.forwardRef<HTMLDivElement>((props, ref) => <div ref={ref} {...props} />)
Expected output
// Generated by dts-bundle-generator v5.9.0
/// <reference types="prop-types" />
/// <reference types="react" />
/// <reference types="scheduler" />
import { ReactElement } from "react";
export declare function Test(): ReactElement;
export declare const ForwardedRef: React.ForwardRefExoticComponent<React.RefAttributes<HTMLDivElement>>;
export {};
Actual output
// Generated by dts-bundle-generator v5.9.0
/// <reference types="prop-types" />
/// <reference types="react" />
/// <reference types="scheduler" />
export declare function Test(): ReactElement;
export declare const ForwardedRef: React.ForwardRefExoticComponent<React.RefAttributes<HTMLDivElement>>;
export {};
Additional context Add any other context about the problem here (CLI options, etc)
tsconfig.json
{
"compilerOptions": {
"jsx": "react",
"lib": ["DOM", "ES2015", "ES2016"],
"esModuleInterop": true,
"skipLibCheck": true
}
}
package.json
{
"dependencies": {
"dts-bundle-generator": "^5.9.0",
"react": "^17.0.2",
"@types/react": "^17.0.19"
}
}
Command
› dts-bundle-generator index.tsx -o index.d.ts
Compiling input files...
Processing index.tsx
Library "react" will be added via reference directive
Library "prop-types" will be added via reference directive
Library "scheduler" will be added via reference directive
Writing index.tsx -> index.d.ts
Checking generated files...
Compiler option "skipLibCheck" is disabled to properly check generated output
index.d.ts(7,33): error TS2304: Cannot find name 'ReactElement'.
Error: Compiled with errors
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Missing support for destructuring in `import … = <namespace ...
TypeScript Version: 2.6.1 Intent To be able to export imports (using allowSyntheticDefaultImports) and not run into the dreaded voldemort ...
Read more >Typescript can not import with out extention - Stack Overflow
I am basically a noob at Typescript and webpack and while learning it I faced with a Major Issue. The Import statement has...
Read more >Refactor React Imports - JavaScript in Plain English
First I created a new file named Imports.js in my src folder. ... All you have to do now is pick which component...
Read more >How To Use Modules in TypeScript | DigitalOcean
Since your src/vectors.ts is only importing two classes to later re-export them, you can use an even briefer form of the syntax:.
Read more >Documentation - Modules - TypeScript
TypeScript Specific ES Module Syntax. Types can be exported and imported using the same syntax as JavaScript values: ts. // @filename: animal.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for the details.
Perhaps I need to rephrase my question.
allowedTypesLibraries: ['react']
option will only work withconst HelloWorld: React.FC = () => null;
code.My library has over 100 components with
FC
type instead ofReact.FC
. SoimportedLibraries: ['react']
is the only working solution otherwise you getlib/index.d.ts(1,18): error TS2304: Cannot find name 'FC'.
error. FC must be imported in .d.ts file.Yep, that’s correct (and iirc this is the default behaviour for now right? I mean you don’t need to even specify
allowedTypesLibraries
explicitly to achieve this, after #170 it will be changed).