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

tsc correctly raises TS errors - tsup builds and ignores errors #609

Open
NixBiks opened this issue Apr 13, 2022 · 7 comments
Open

tsc correctly raises TS errors - tsup builds and ignores errors #609

NixBiks opened this issue Apr 13, 2022 · 7 comments
Labels
bug Something isn't working plugin: dts

Comments

@NixBiks
Copy link

NixBiks commented Apr 13, 2022

If I run pnpm exec tsc --noEmit then I get 5 errors. If I run pnpm 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

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@NixBiks NixBiks closed this as completed Apr 13, 2022
@NixBiks NixBiks reopened this Apr 13, 2022
@egoist
Copy link
Owner

egoist commented Apr 14, 2022

I need a repro to tell if this is a bug

@OmgImAlexis
Copy link

OmgImAlexis commented Aug 1, 2022

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.

@egoist egoist added bug Something isn't working and removed need repro labels Aug 2, 2022
@egoist
Copy link
Owner

egoist commented Aug 2, 2022

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?

@elibosley
Copy link

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

@await-ovo
Copy link
Contributor

await-ovo commented Nov 8, 2022

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(Swatinem/rollup-plugin-dts#41 (comment)) ~

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 :)

@vktrl
Copy link

vktrl commented Dec 23, 2022

Ran into the same problem, maybe the docs should mention that you can't rely on the --dts flag for type checking?

@riverrz
Copy link

riverrz commented Dec 24, 2022

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\""
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working plugin: dts
Projects
None yet
Development

No branches or pull requests

7 participants