Closed ghostdevv closed 2 years ago
bump
I think the problem comes from your handcrafted .d.ts
file:
It indeed is missing a declare
modifier.
@Swatinem I tested this and with exporting a enum with:
export declare enum TestEnum {
A,
B,
C,
D
}
it doesn't work
the same。tsc generate file test.d.ts
export declare type PushEvent = {...}
but,dts plugin roll the definition index.d.ts
declare type PushEvent = {...}
Lost export
,my user cannot import this definition
@everlose Well are you exporting it again from the index.d.ts
?
the same。tsc generate file
test.d.ts
export declare type PushEvent = {...}
but,dts plugin roll the definition
index.d.ts
declare type PushEvent = {...}
Lost
export
,my user cannot import this definition
I have this issue too.
@everlose Well are you exporting it again from the index.d.ts?
@Swatinem How to export
from index.d.ts
? index.d.ts
is generated by this plugin. these decalations types were exported from test.d.ts
but when it got bundled by this plugin into a single index.d.ts
, that export
keyword is lost in that index.d.ts
My user now cannot import those definition because the export
keyword is lost in index.d.ts
I mean obviously if you want something be exported from index.d.ts
that originally lives in test.d.ts
you gotta export { PushEvent } from "./test";
or something similar.
Hi @Swatinem . Thankyou for replying
Let me explain you through an example. I have setup a test repo to show you the exact problem.
git clone https://github.com/ashuvssut/rollup-ts-test && cd rollup-ts-test && yarn && yarn dev
So what happened? After we did rollup -c
, TS compiler will generate the declatation .d.ts
files in the /@types (in tsconfig: declarationDir: "/@types"
)
so you will see something like this:-
@types/
|---- index.d.ts
|---- types.d.ts
dist/
tsconfig.json
rollup.config.js
.
.
.
.
IMPORTANT Observe that
index.d.ts
&types.d.ts
haveexport
keywords that you were asking about
So, that index.d.ts
is next fed to to rollup-plugin-ts (see rollup.config.js
). this will result in bundling all @types/*.d.ts
file to dist/index.d.ts
Now Observe the problem in dist/index.d.ts
. We lost the export
keywords that were present in d.ts
files in @types/
Hope this helps. Thanks
Yes, the only thing you are exporting from index.ts
is this:
export { THEMES };
The other things are not being exported because you didn’t explicitly tell them to be. You can still refer to the other things indirectly, via typeof THEMES
, if you absolutely want to. Otherwise you need to specifically re-export the stuff.
@Swatinem yes thankyou. It makes sense now
I gave the plugin input
option as input: "./@types/index.d.ts",
and that's why only exported members of index.d.ts had the export
keyword.
As you suggested we have to re-export through index.ts
. I followed that and it worked
But now suppose there are 100+ such types from different different
EDIT: We can use JS Barreling technique to re-export at once. types.ts
files... now I have to re-export all those 100+ types through index.ts
.😫 I wish there was a easy way to do that
Anyways thankyou very much for bearing with my silly comments and questions. I am just a TS newbie studying in college😅
I would like to reclarify the original purpose of this issue. When using a enum in a ts file the built dts does not have a enum prefixed with the declare
or export
modifier. Which is invalid. I have the repro here and you can see the source and build result.
Your repro has a index.ts
that does a export * from './test';
, only that you have both a test.ts
and test.d.ts
file. It looks like the typescript resolution prefers the .d.ts
file, which is missing the declare
keyword.
It would be nice to resolve that ambiguity first, and create a repro that starts with valid .d.ts
files. The .ts
mode is a maintenance nightmare.
Your repro has a index.ts that does a export * from './test';, only that you have both a test.ts and test.d.ts file. It looks like the typescript resolution prefers the .d.ts file, which is missing the declare keyword.
it is my understanding and assumption from extensive use of enums that you do not require the declare keyword when you are exporting an enum.
It would be nice to resolve that ambiguity first, and create a repro that starts with valid .d.ts files. The .ts mode is a maintenance nightmare.
You are right about this
I will close this issue as I am unable to re-reproduce this! thank you for your time
Your repro has a index.ts that does a export * from './test';, only that you have both a test.ts and test.d.ts file. It looks like the typescript resolution prefers the .d.ts file, which is missing the declare keyword.
it is my understanding and assumption from extensive use of enums that you do not require the declare keyword when you are exporting an enum.
It would be nice to resolve that ambiguity first, and create a repro that starts with valid .d.ts files. The .ts mode is a maintenance nightmare.
You are right about this
I will close this issue as I am unable to re-reproduce this! thank you for your time
Randomly found this looking for a typescript solution
declaring the enum as an export did it for me. Appreciate the tip 👍
export enum MyEnum { PROP1, PROP2 };
Checklist
node-resolve
are known to cause issues..d.ts
files generated by TypeScript. The plugin can consume.ts
and even.js
files (withallowJs: true
), but this is known to cause issues.@types
. The plugin ignores these by default, unlessrespectExternal
is set.@types
can contain hand-crafted code which is known to cause issues.I am running this on my code and it works fine, well I am using http://npmjs.com/tsup to bundle my typescript code for esm and cjs platforms.
I ran into a issue with it not generating
declare
on enums when used a certain way, I created a repro here: https://github.com/ghostdevv/dts-plugin-enum-repoI know it doesn't ticket checkbox 2 but I think this is within the scope of a bug