Skip to main content
Module

x/tsafe/test/withDefaults.types.ts

🔩 The missing TypeScript utils
Go to Latest
File
/* eslint-disable @typescript-eslint/ban-ts-comment *//* eslint-disable @typescript-eslint/no-unused-vars *//* eslint-disable @typescript-eslint/no-explicit-any */
import { assert } from "../assert.ts";import { withDefaults } from "../lab/withDefaults.ts";import type { Equals } from "../Equals.ts";
const x: <T>() => T = null as any;
//@ts-ignorefunction test<T, U, V>() { const f: (params: { foo: T | undefined; bar: U }) => V = x<any>(); const got = withDefaults(f, { "foo": x<T>() });
const expected: ( params: { bar: U; } & { defaultsOverwrite?: { foo?: [T | undefined]; }; }, ) => V = x<any>();
assert<Equals<typeof got, typeof expected>>();}
//@ts-ignorefunction test<T, U, V>() { const f: (params: { foo: T; bar: U }) => V = x<any>(); const got = withDefaults(f, { "foo": x<T>() });
const expected: ( params: { bar: U; } & { defaultsOverwrite?: { foo?: [T]; }; }, ) => V = x<any>();
assert<Equals<typeof got, typeof expected>>();}
//@ts-ignorefunction test<T, U, V>() { const f: (params: { foo?: T; bar: U }) => V = x<any>(); const got = withDefaults(f, { "foo": x<T>() });
const expected: ( params: { bar: U; } & { defaultsOverwrite?: { foo?: [T | undefined]; }; }, ) => V = x<any>();
assert<Equals<typeof got, typeof expected>>();}
//@ts-ignorefunction test<T>() { // eslint-disable-next-line @typescript-eslint/ban-types const f: (params: {}) => T = null as any;
//@ts-expect-error withDefaults(f, { "foo": null as any });}
//@ts-ignorefunction test<T>() { // eslint-disable-next-line @typescript-eslint/ban-types const f: (params: { bar: number }) => T = null as any;
//@ts-expect-error withDefaults(f, { "foo": null as any });}
//@ts-ignorefunction test<T>() { // eslint-disable-next-line @typescript-eslint/ban-types const f: (params: {}) => T = null as any;
withDefaults(f, {});}
//@ts-ignorefunction test<T>() { // eslint-disable-next-line @typescript-eslint/ban-types const f: (params: { foo: number; bar: string }) => T = null as any;
//@ts-expect-error withDefaults(f, { "foo": null as any, "baz": "" });}
//@ts-ignorefunction test<T, U, V>() { const f: (params: { a: U; b: T }) => V = x<any>();
const fWd = withDefaults(f, { "a": x<any>() });
//@ts-expect-error const got = fWd({ "b": x<any>(), "defaultsOverwrite": { "a": [undefined] } });}