wessberg / rollup-plugin-ts

A TypeScript Rollup plugin that bundles declarations, respects Browserslists, and enables seamless integration with transpilers such as babel and swc
MIT License
496 stars 32 forks source link

No declaration generated with components + decorators #38

Closed dattebayorob closed 5 years ago

dattebayorob commented 5 years ago

When a component wrapped by a decorator is exported, rollup-plugin-ts cant generate de .d.ts interface . I noticed it with mobx-react observer, but with others decorator as well will reproduce same issue.

Here I created a component using withRouter from react-router-dom, and the output of index.d.ts is:

##dist/index.d.ts
import React from "react";
declare const Col: React.FC;
interface RowProps extends React.HTMLAttributes<HTMLDivElement> {
    children?: React.ReactNode;
}
declare const Row: React.FC<RowProps>;
export { Row, Col, Router };

When exporting component without decorators, rollup-plugin-ts recognize types

##dist/index.d.ts
import React from "react";
declare const Col: React.FC;
interface RowProps extends React.HTMLAttributes<HTMLDivElement> {
    children?: React.ReactNode;
}
declare const Row: React.FC<RowProps>;
interface Props {
    test?: string;
}
declare const Router: React.FC<Props>;
export { Row, Col, Router };

rollup-plugin-ts version: 1.1.73 I'm using tsdx, let me now if this is the wrong place to report it.

wessberg commented 5 years ago

Hi there. Thanks for reporting this issue. I'm hoping you can provide me with a little more details, because I'm a little confused as to the decorator part of the issue? I don't see any decorators in any of the linked commits.

dattebayorob commented 5 years ago

Ops, I'm sorry, herehere

dattebayorob commented 5 years ago

In my case, the Router Props on .d.ts arent generated when a component decorated is exported.

The rollup-plugin-typescript2 ignores decorators on type definitionss, and generate .d.ts with the props Interface only.

wessberg commented 5 years ago

Ops, I'm sorry, herehere

I still don't see any decorators 🙂 But I do see the export being assigned to the result of wrapping it in a function invocation. I'll look into it and set up a test case.

dattebayorob commented 5 years ago

Oh, thanks, in react ecosystem I know HOCs as decorator / annotations even in functional components that doesn't accept experimentalDecorators, sorry for the confusion

@withRouter()
class Component{}
withRouter(() =>{})
wessberg commented 5 years ago

This issue has been fixed in v1.1.74