Files
Janka UrygaandGitHub 669c52e393 typechecking inputs/outputs in action transform tests (#75935)
This PR attempts to add typechecking to the server actions tests
fixtures in order to add an extra layer of validation against compiler
bugs. (there's a couple!). Unfortunately the tests were pretty
loosey-goosey around undefined variables, so there's a lot of noise in
adding missing imports for `Button` etc. i tried to call out the
interesting changes via PR comments.

Note that this is a bit limited, because we often have to rely on
typescript inferring some sensible types for the outputs -- see e.g. the
issue with `24/output.js` mentioned below. In case typescript can't
infer sensible types for something, we can just exclude that file from
checking. this seems to be pretty rare, so i think it's okay.

We should also definitely add typechecking to the other fixture folders,
but this PR is already big, so i want to do that piecemeal.

### TODO
- [x] invoke the typechecker in CI
- added a `check-compiler-fixtures` script that runs as part of
`types-and-precompiled` (open to feedback, maybe this isn't the right
place?)
- [x] figure out how to make `tsc` error on
`crates/next-custom-transforms/tests/fixture/server-actions/server-graph/51/output.js`,
where we're referencing a non-existent variable `$$RSC_SERVER_ACTION_0`.
right now, it emits no errors
- this is a compiler bug, and i want to catch bugs like this in the
future
  - solution: https://github.com/vercel/next.js/pull/75944
- [x] figure out why `tsc` is complaining about a type mismatch in
`crates/next-custom-transforms/tests/fixture/server-actions/server-graph/24/output.js`
- we can work around this by loosening the types for
`registerServerReference`, but i'd rather we didn't have to do that
- this seems to be a bizarre TS behavior where `fn.bind(...)` makes all
the params optional in JS files. ignoring this for now
2025-02-24 16:59:34 +00:00

82 lines
1.0 KiB
JavaScript

import ANYTHING from 'anything'
import f, { f1, f2 } from 'foo'
import { Button } from 'components'
const f3 = 1
var f4
let f5
const [
f6,
[f7, ...f8],
{ f9 },
{
f10,
f11: [f12],
f13: f14,
f15: { f16 },
...f17
},
...f18
] = ANYTHING
if (true) {
const g19 = 1
}
function x() {
const f2 = 1
const g20 = 1
}
export function y(p, [p1, { p2 }], ...p3) {
/** @type {any} */
const f2 = 1
const f11 = 1
const f19 = 1
if (true) {
const f8 = 1
}
async function action() {
'use server'
const f17 = 1
if (true) {
const f18 = 1
const f19 = 1
}
console.log(
f,
f1,
f2,
f3,
f4,
f5,
f6,
f7,
f8,
f2(f9),
f12,
f11,
f16.x,
f17,
f18,
p,
p1,
p2,
p3,
// @ts-expect-error: deliberately undefined variable
g19,
// @ts-expect-error: deliberately undefined variable
g20,
globalThis
)
}
return <Button action={action}>Delete</Button>
}