Open kasperpeulen opened 1 year ago
We were able to workaround this by using tsc
for types generation:
// tsup.config.ts
import { defineConfig } from "tsup";
export default defineConfig({
entry: ["src/index.ts"],
format: ["esm"],
onSuccess: "yarn tsc -p tsconfig.tsup.json && echo 'Rebuilt'",
});
// tsconfig.tsup.json
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.json",
"include": ["src"],
"compilerOptions": {
"noEmit": false,
"emitDeclarationOnly": true,
"outDir": "dist",
"rootDir": "src"
}
}
That also fixes https://github.com/egoist/tsup/issues/1050
Independent of tsup, beware of this change in TypeScript 5.5 regarding reference directives: https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/
You need to add preserve="true"
to the directives if you want them to be preserved in the output
@maxpatiiuk, it seems that tsup does not respect preserve="true"
.
When /// <reference types="jest" preserve="true" />
is added to the tsup entry src/index.ts
file, it is stripped from the resulting .d.ts file.
We are using tsup in storybook, but we seem to have a problem with the declaration files emitted by tsup.
This is a minimal reproduction of the file:
When I just try to generate type declaration with tsc, it will output this:
But when I do same with tsup, the triple slash types directive is missing:
Can I somehow configure
tsup
to generate those directives. It seems like this is meant to be included:https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#-reference-types-
This also breaks when building storybook in angular projects. When I manually add the directive it works again:
One workaround I found is setting the banner:
Upvote & Fund