question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tsc correctly raises TS errors - tsup builds and ignores errors

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
await-ovocommented, 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(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 😃

0reactions
shivam123425commented, 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\""
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to (temporarily!) ignore errors during a TypeScript migration
Tsc -silent lets you ignore certain TypeScript errors. By ignoring the errors that came from code not yet migrated, I could add TypeScript...
Read more >
TypeScript's @ts-expect-error: The best way to ignore errors
One of the sneakier new awesome features of the recently released TypeScript 3.9 was the new comment `// @ ts -expect- error `....
Read more >
Typescript: Why doesn't visual studio code report the same ...
When I've done this the errors will appear on the command line. ... VS Code may report errors for incompatible types whereas tsc...
Read more >
ts-loader - npm
Start using ts-loader in your project by running `npm i ... The build should fail on TypeScript compilation errors as of webpack 2....
Read more >
how to generate tsconfig.json Code Example
npx tsc --init. ... TS_NODE_PROJECT="path/to/tsconfig.json" node --loader ts-node/esm . ... Error: You have both a tsconfig.json and a jsconfig.json ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found