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.

Opting out of typescript checks in Next 9.0+

See original GitHub issue

Feature request

Is your feature request related to a problem? Please describe.

In Next.js <= 8.1.1 we’ve been using @zeit/next-typescript, which essentially meant passing ts and tsx files through @babel/preset-typescript. Because of that, imperfections in typings did not prevent the dev server from refreshing or the production app from building. That felt like a convenient DX, given that proper ts checks could be done via yarn lint:tsc in CI (this script would call tsc --noEmit).

I’ve been playing with the latest canary (<= 8.8.1-canary.61) in a couple of new projects and noticed a change in the DX, which I found somewhat distracting. Because TypeScript compiler is now continuously used during development, even a slightest type-related imperfection crashes the app.

The problem with this approach is that it is much harder to experiment with the new stuff. E.g. I can’t create a new component, then call it somewhere as <NewComponent foo={data} bar={42} /> and only then implement the typings for the props and handle them. Redundant props are detected by tsc as soon as I mention them, which prevents the app from refreshing. That locks the development process into a certain sequences of steps, which don’t always feel natural.

Given that I can run yarn lint:tsc separately, I don’t even mind being able to next build in spite of type-related imperfections, as long as the produced JavaScript is sane. This can be useful, for example, when deploying a preview app for a PR that has not been finished yet (the new functionality works, but typings still need a bit of polishing).

Describe the solution you’d like

I understand the motivation behind the new way of tracking TS errors. If I remember correctly, create-react-app does the same. Crashing at each TypeScript imperfection can indeed be useful. For example, it won’t let newcomers do the wrong thing and won’t overload them with the notion of different kinds of errors.

However, some developers like myself will probably like to avoid tsc-related crashes both during next dev and next build and just rely on yarn lint:tsc as before. Not only this will make experimentation less painful, but also ease project migration into Next.js. We have a few non-Next.js React projects containing a mix of ts and js files. Renaming *.js to *.ts creates quite a few tsc errors, which can’t be fixed in one go. The only option is to ensure each new PR does not increase the number of tsc errors until zero is reached.

How feasible would it be to implement a flag in next.config.js? Something like:

module.exports = {
    skipTypescriptChecking: true
    // or
    typescript: {
       transpileOnly: true // same as ts-node --transpile-only
    }
}

Seems like with the flag like that there’s even no need to create tsconfig.json. Next app can sit in a yarn workspace inside a monorepo, where yarn lint:tsc uses a manually crafted top-level tsconfig.json.

Describe alternatives you’ve considered

Using a stable Next.js release (8.1.1) works well, but it won’t be the latest framework version forever.

Additional context

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:54
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

48reactions
callumlockecommented, Aug 2, 2019

@Timer please reconsider your position on this.

I’m not sure if we want to give users the easy control to opt-out of type-checking

Just to reassure you, no one here is trying to to “opt out of type-checking”, otherwise we’d just switch to plain JavaScript! We just want to opt out of type-checking during the Next build.

I think it’s great that you offer a simple way to fail the Next build on type errors, for the many users who still prefer that behaviour. And I don’t even mind that it’s the default. But it is frustrating that you don’t trust our judgement when we want to opt out of it. Our preferred workflow is no less rigorous or valid. We just enforce type-checking at a different point in the lifecycle, along with our unit tests and linters. Some teams enforce it as a pre-commit hook, others enforce it as a PR merge condition or during a CI deployment job.

25reactions
dmitwebcommented, Jun 27, 2019

@kachkaev it may helps u, i use this in canary version my project from the first version next with ts

    config.plugins = config.plugins.filter(plugin => {
      if (plugin.constructor.name === 'ForkTsCheckerWebpackPlugin') return false;
      return true;
    });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignoring TypeScript Errors - next.config.js
Next.js reports TypeScript errors by default. Learn to opt-out of this behavior here.
Read more >
Using $any() To Temporarily Disable Type-Checking Within A ...
Ben Nadel demonstrates how to use the $any() pseudo-function to bypass type-checking within an Angular component template when the ...
Read more >
Template type checking - Angular
Use the $any() type-cast function in certain contexts to opt out of type-checking for a part of the expression; Disable strict checks entirely...
Read more >
Announcing TypeScript 4.9 - Microsoft Developer Blogs
TypeScript can check these types to make sure we're not making mistakes in our programs so we can code with confidence.
Read more >
The --strict Compiler Option in TypeScript - Marius Schulz
June 9, 2017 ... Future versions of TypeScript might add additional type checking options to this set. ... #Opting Out of Certain Options....
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