Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No .d.ts created after update to 0.10.0 #268

Closed
dattebayorob opened this issue Oct 17, 2019 · 26 comments · Fixed by #287
Closed

No .d.ts created after update to 0.10.0 #268

dattebayorob opened this issue Oct 17, 2019 · 26 comments · Fixed by #287
Labels
kind: bug Something isn't working scope: upstream Issue in upstream dependency topic: v0.10.x Issues related to broken builds in v0.10.x / @wessberg/rollup-plugin-ts

Comments

@dattebayorob
Copy link

dattebayorob commented Oct 17, 2019

Current Behavior

in 0.10.0

//index.ts
import { PrivateRoute, PublicRoute } from "./components";

export {
  PrivateRoute,
  PublicRoute
}

will generate

//index.d.ts
export { PrivateRoute, PublicRoute };

and directories of components with .d.ts aren't created
img

Expected behavior

In 0.9.3 the .d.ts are created:
img

//index.d.ts
import { PrivateRoute, PublicRoute } from "./components";
export { PrivateRoute, PublicRoute };

Suggested solution(s)

Additional context

Your environment

Software Version(s)
TSDX >=0.10.0
TypeScript ^3.6.4
Browser
npm/Yarn v1.17.3
Operating System Arch
@tabuckner
Copy link

I'm running into a similar issue and just assumed it was a quirk with the project.

@dattebayorob Was this working for you on a previous version?

@tabuckner

This comment has been minimized.

@tabuckner
Copy link

@dattebayorob I've updated your comment above.

I can also confirm that this seems to be introduced in the first 0.10.0 release

@tabuckner
Copy link

tabuckner commented Oct 17, 2019

Maybe this?
image

@tabuckner
Copy link

potential related bug?
wessberg/rollup-plugin-ts#31

@tabuckner
Copy link

it looks like we swapped rollup-plugin-typescript2 for @wessberg/rollup-plugin-ts

image

I've got a few other projects that are using rollup and rollup-plugin-typescript2, those are working in the way we'd expect.

There was almost definitely a reason that we switched to the new package though, right?

@tabuckner
Copy link

@jaredpalmer
Copy link
Owner

@wessberg?

@jaredpalmer
Copy link
Owner

It seems like this plugin is not yet stable. I think we should go back to Rollup-typescript2

@sadsa
Copy link
Contributor

sadsa commented Oct 17, 2019

@jaredpalmer - was this not part of a fix for - Support for async/await in rollup plugins?
e.g. vladshcherbin/rollup-plugin-copy#16

@wessberg
Copy link

wessberg commented Oct 17, 2019

@tabuckner, The reason why you're seeing a different file structure now in terms of where declaration files are emitted to is that rollup-plugin-ts bundles your declaration files and follows Rollups file structure. Meaning, a declaration file is generated per chunk. Previously, you were seeing declarations being generated (not bundled) that simply followed the source structure, even though the folders only contained declarations. So that at least explains the difference in the file structure.

If you instead do:

export {PrivateRoute, PublicRoute} from "./components";

Does that produce correct declarations inside index.d.ts?

I haven't verified it yet, but I think what's happening is that the tree-shaking step of the declaration bundling phase of rollup-plugin-ts determines that the two import bindings are unused given that they are referenced only by the ExportSpecifiers in the ExportDeclaration that reexports them. I'll look into it.

There was almost definitely a reason that we switched to the new package though, right?

I really don't know why, but I think the combination of declaration bundling, ease of combining with Babel and support for plugins with async functions (to work around an object-hash limitation) were the primary reasons.

@dattebayorob
Copy link
Author

dattebayorob commented Oct 18, 2019

If you instead do:

export {PrivateRoute, PublicRoute} from "./components";

Does that produce correct declarations inside index.d.ts?

No, the .d.ts creates a

export { PrivateRoute, PublicRoute };

@tabuckner
Copy link

@wessberg Here's an repro repo that shows the issues I ran into with v0.10.0 of tsdx and on.

It's not the exact scenario you outline and @dattebayorob confirmed, but it does seem to be related.

https://github.com/tabuckner/tsdx-0.10.x-type-defs-repro

@dattebayorob
Copy link
Author

I will try to setup with the @wessberg/rollup-plugin-ts now, I need a async plugin now, and the typescript2 hack to get it to work doesn't seem like a good idea

@dattebayorob
Copy link
Author

dattebayorob commented Oct 18, 2019

ombination of declaration bund

On src/index.ts

export * from './components'; export * from './annotations'; export * from './templates';

The generated dist/index.d.ts
export {};

@jaredpalmer
Copy link
Owner

@dattebayorob @tabuckner what version of node are you all using?

@tabuckner
Copy link

v10.15.3

I'll try with some other versions as well.

@tabuckner
Copy link

image

declare const sum: (a: number, b: number) => number;
declare const log: (str: string) => void;
export * from "../src/util/cool-thing/models/cool-thing-input";
export * from "../src/util/cool-thing/models/cool-thing-output";
export { sum, log };

@tabuckner
Copy link

image

declare const sum: (a: number, b: number) => number;
declare const log: (str: string) => void;
export * from "../src/util/cool-thing/models/cool-thing-input";
export * from "../src/util/cool-thing/models/cool-thing-output";
export { sum, log };

@dattebayorob
Copy link
Author

I'm on 11.15.0

@jaredpalmer
Copy link
Owner

Is this the default or did you use it with an async Rollup plugin?

@dattebayorob
Copy link
Author

With default plugins

@wessberg
Copy link

@wessberg Here's an repro repo that shows the issues I ran into with v0.10.0 of tsdx and on.

It's not the exact scenario you outline and @dattebayorob confirmed, but it does seem to be related.

https://github.com/tabuckner/tsdx-0.10.x-type-defs-repro

Thanks for the repro. I'll take a look at it and will report back here.

@wessberg
Copy link

wessberg commented Oct 19, 2019

Alright, I've fixed the issues and released v1.1.73. There were two of them:

  • Directory imports were being used coupled with Node module resolution. There was an issue related to this, which has been resolved.
  • Module Specifiers following the form ./cool-thing-input.interface were being used, and .interface was being mistakenly interpreted as the file extension when reading from disk

Here's the declaration output based on your repro in the new version:

interface ICoolThingInput {
    message: string;
    id?: number;
}
interface ICoolThingOutput {
    name: string;
    id: number;
    message: {
        text: string;
        code: number;
    };
}
declare const sum: (a: number, b: number) => number;
declare const log: (str: string) => void;
declare const doCoolThings: (input: ICoolThingInput) => ICoolThingOutput;
export { sum, log, doCoolThings, ICoolThingInput, ICoolThingOutput };

I'm unaware if this also fixes the issue that the original issue author had since I have no repro for it, but I hope so.

@dattebayorob
Copy link
Author

dattebayorob commented Oct 20, 2019

I did some tests with the new rollup-plugin-ts:
export components manually:

import { Row, Col } from './components';

Will generate declarations correctly:

import React from "react";
declare const Col: React.FC;
declare const Row: React.FC;
export { Row, Col };

But if a export * :

export * from './components'

lends to

export {};

Here a repo sample

@wessberg
Copy link

wessberg commented Nov 9, 2019

@dattebayorob, The issue you reported has been fixed in the latest version of rollup-plugin-ts.

@agilgur5 agilgur5 added kind: bug Something isn't working scope: upstream Issue in upstream dependency topic: v0.10.x Issues related to broken builds in v0.10.x / @wessberg/rollup-plugin-ts labels Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working scope: upstream Issue in upstream dependency topic: v0.10.x Issues related to broken builds in v0.10.x / @wessberg/rollup-plugin-ts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants