changing tsconfig.json target from "es5" to "esnext" #14390
Replies: 4 comments 8 replies
-
I'm also curious about this question. Perhaps If anybody can provide more insight, please let us know. Update: I think I figured it outI think I understand why the default Sometimes you'll use some >ES5 syntax that Babel doesn't know what to do with because there's no ES5 equivalent polyfill. If you use For example, here is the problem I was having: import { Footer } from './Footer'
import { render } from '@testing-library/react'
let component: HTMLElement
beforeEach(() => {
component = render(<Footer />).getByTestId('footer')
})
it("doesn't contain broken links", async () => {
const links = component.querySelectorAll('a') as any
// TS Error on `links` in for loop: TS2569: Type 'NodeListOf ' is not
// an array type or a string type. Use compiler option
// '--downlevelIteration' to allow iterating of iterators.
for (const link of links) {
const response = await global.fetch(link.href)
expect(response.status).toBe(200)
}
}) This code is just for running tests. The const links = component.querySelectorAll('a') as any |
Beta Was this translation helpful? Give feedback.
-
Top level await is not compatible with typescript: {
ignoreBuildErrors: true,
}, |
Beta Was this translation helpful? Give feedback.
-
It should be safe. The value of
As you can see from the screenshot, bundle sizes are identical. At the time of writing, Next always uses I guess the reason why Next defaults to |
Beta Was this translation helpful? Give feedback.
-
You can and should set target based on your node version assuming you aren't on bleeding node. Check this page for which recommended target: https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping |
Beta Was this translation helpful? Give feedback.
-
typescript beginner question: as far as i understand, nextjs uses
tsc
only for type checking andbabel
for compilation -- is it therefore safe to change the default tsconfigtarget: es5
totarget: esnext
for a small perf win?Beta Was this translation helpful? Give feedback.
All reactions