Description
Bug Report
Use of the satisfies
keyword changes the output of the compiler. Vitally important require
statements are missing. Does not appear to happen when using tsc
but only when invoking the compiler programmatically as is done by ts-loader
from the WebPack project.
🔎 Search Terms
satisfies, webpack, ts-loader, 4.9
🕗 Version & Regression Information
This bug only occurs when using the satisfies
keyword.
⏯ Playground Link
Unable to reproduce with Playground so here is a repo showing the issue:
https://github.com/cjdell/typescript-satisfies-missing-modules-references-bug
Also another repo showing the original discovery of the bug including a working WebPack setup and ts-loader
plugin:
https://github.com/cjdell/ts-loader-satisfies-bug
💻 Code
Note: This is fully demonstrated in the above GitHub repo.
import { z } from "zod";
import { isValid } from "./lib";
interface MyObject {
name: string;
}
export const MyObjectSchema = z.object({
name: z.string().refine(isValid),
}) satisfies z.ZodSchema<MyObject>; // Removing the `satisfies` keyword will change the output of the compiler
console.log(MyObjectSchema.parse({ name: 'foo' }));
Output with satisfies
:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MyObjectSchema = void 0;
exports.MyObjectSchema = zod_1.z.object({
name: zod_1.z.string().refine(lib_1.isValid),
});
console.log(exports.MyObjectSchema.parse({ name: 'foo' }));
Output without satisfies
:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MyObjectSchema = void 0;
const zod_1 = require("zod"); // THIS IS MISSING FROM ABOVE
const lib_1 = require("./lib"); // THIS IS MISSING FROM ABOVE
exports.MyObjectSchema = zod_1.z.object({
name: zod_1.z.string().refine(lib_1.isValid),
});
console.log(exports.MyObjectSchema.parse({ name: 'foo' }));
🙁 Actual behavior
As with above, using the satisfies
keyword results in missing require
statements.
🙂 Expected behavior
I expect the use of the satisfies
keyword to have no effect on the compiler's outputted JavaScript.