Open NixBiks opened 2 years ago
I need a repro to tell if this is a bug
Got the exact same issue here, running with --dts
does NOT do any typechecking.
Running tsc
is throwing a load of errors about typescript issues where as tsup --dts
returns nothing at all.
This is currently blocking me.
I can reproduce it with this:
// index.ts
import { bar } from "./bar"
export function foo() {
bar()
}
// bar.ts
export const bar = () => {}
export function unused_error_function() {
let a: string = 1 // <-- type error
return a
}
Seems rollup-plugin-dts doesn't type check unused export
@OmgImAlexis did you have the same code pattern?
Hi 👋 I noticed this coming from functions that are missing import statements. Tsc would pick up the missing imports but tsup --dts wouldn't throw an error for any missing functions
I can reproduce it with this:
// index.ts import { bar } from "./bar" export function foo() { bar() } // bar.ts export const bar = () => {} export function unused_error_function() { let a: string = 1 // <-- type error return a }
Seems rollup-plugin-dts doesn't type check unused export
@OmgImAlexis did you have the same code pattern?
it seems that rollup-plugin-dts doesn't type check bar.ts
at all, code like this will also not throw errors:
// index.ts
import { bar } from "./bar"
export function foo() {
bar()
}
// bar.ts
export const bar = () => {
let b:string = 1 // <-- type error
return b;
}
Here are my thoughts:
rollup-plugin-dts use typescript's api(program.emit
) generate declaration file for index.ts
, then use Rollup bundle the generated code. dts for index.ts
will be :
export declare function foo(): void;
This has nothing to do with ./bar.ts
, so Rollup will not resolve, tranform ./bar.ts
will also not do type checking~
I'm not sure if it is a bug of rollup-plugin-dts, seems that the recommended way to use this plugin is with generated dts with tsc(https://github.com/Swatinem/rollup-plugin-dts/issues/41#issuecomment-503550069) ~
Can we use tsc generate declaration files and then use rollup-plugin-dts or api-extractor bundle dts files? this also should be no problem with type check :)
Ran into the same problem, maybe the docs should mention that you can't rely on the --dts flag for type checking?
I ran into the same problem :( I had to use tsc
and tsc-watch
package and run tsup
in its success callback. The dev and build step looks like this:
"scripts": {
"build": "tsc && tsup --env.NODE_ENV production",
"dev": "tsc-watch --onSuccess \"tsup --env.NODE_ENV production\""
}
Any update on this please.
I was debugging what is happening, and it seems that when rollup-plugin-dts calls typescript, typescript compiler correctly type-checks the files (since they are part of the ts.Program), but then those type errors are not reported by ts.Program.emit()
To be more specific, as part of ts.Program.emit()
this TypeScript function is called:
function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationToken, skipDiagnostics?: boolean) {
// Ensure we have all the type information in place for this file so that all the
// emitter questions of this resolver will return the right information.
if (!skipDiagnostics) getDiagnostics(sourceFile, cancellationToken);
return emitResolver;
}
(from src/compiler/checker.ts
)
Where getDiagnostics()
correctly returns the diagnostics for the type errors - as the comment suggests, they are supposed to be retrieved by something else somewhere else, but that is not happening...
rollup-plugin-dts
is now in maintenance mode.
The maintainer misleadingly mass-closed all issues as "completed" 😮💨
It looks like type errors are correctly emitted if I am using TSUP's "experimentalDts": true,
option over "dts": true,
(which uses @microsoft/api-extractor
under the hood instead of rollup-plugin-dts
).
However experimentalDts
still feels experimental (it doesn't emit .d.ts
files into correct place in my project; and it logs messages to console that are not disableable even when tsup is run with --silent
)
Could tsup possibly use @microsoft/api-extractor
for import typechecking and then switch back to the rollup dts plugin for dts generation? :/
If I run
pnpm exec tsc --noEmit
then I get 5 errors. If I runpnpm exec tsup src/index.ts --dts
then I 0 errors.I realize I don't provide enough info here but first I just want to ask if this isn't a bug?
Upvote & Fund