Support checked closed generic portable bindings
This commit is contained in:
@@ -51,3 +51,39 @@ for (const target of ["browser", "server"])
|
||||
`dist/portable-reader/composite/${name}-${target}.ts`,
|
||||
generatePortableTypeScriptBindings(composite.definition.bindingSchema, revision, { target }),
|
||||
);
|
||||
|
||||
const { portableGenericPlan } = await import("./portable-generic-fixture.js");
|
||||
const generic = portableGenericPlan();
|
||||
const genericPackage = generic.definition.bindingSchema.packages[0]!;
|
||||
await mkdir("dist/portable-reader/generic", { recursive: true });
|
||||
for (const target of ["browser", "server"]) {
|
||||
await writeFile(
|
||||
`dist/portable-reader/generic/${target}.ts`,
|
||||
generatePortableTypeScriptBindings(generic.definition.bindingSchema, genericPackage.revisionId, { target }),
|
||||
);
|
||||
}
|
||||
const stringEntry = genericPackage.exports.find((e) => e.inputType.kind === "scalar")!;
|
||||
const listEntry = genericPackage.exports.find((e) => e.inputType.kind === "list")!;
|
||||
await writeFile(
|
||||
"dist/portable-reader/generic/implementation.ts",
|
||||
`
|
||||
import { createRegistry, type PortableImplementation } from "./gen/qx.js";
|
||||
export const registry = createRegistry({
|
||||
${JSON.stringify(stringEntry.displayName)}: context => context.input.toUpperCase(),
|
||||
${JSON.stringify(listEntry.displayName)}: context => context.input.map(value => value + 1n),
|
||||
});
|
||||
// The specialization must retain its actual contract, not become unknown or any.
|
||||
const negative: PortableImplementation = {
|
||||
// @ts-expect-error a string specialization cannot return a number
|
||||
${JSON.stringify(stringEntry.displayName)}: context => context.input.length,
|
||||
${JSON.stringify(listEntry.displayName)}: context => {
|
||||
// @ts-expect-error input collections are read-only
|
||||
context.input.push(0n);
|
||||
// @ts-expect-error integer values are exact bigint, not number
|
||||
const lostPrecision: number = context.input[0]!;
|
||||
return context.input;
|
||||
},
|
||||
};
|
||||
void negative;
|
||||
`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user