From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../tests/cts/checkout/src/common/util/types.ts | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 dom/webgpu/tests/cts/checkout/src/common/util/types.ts (limited to 'dom/webgpu/tests/cts/checkout/src/common/util/types.ts') diff --git a/dom/webgpu/tests/cts/checkout/src/common/util/types.ts b/dom/webgpu/tests/cts/checkout/src/common/util/types.ts new file mode 100644 index 0000000000..dfd5e4b5ea --- /dev/null +++ b/dom/webgpu/tests/cts/checkout/src/common/util/types.ts @@ -0,0 +1,59 @@ +/** Forces a type to resolve its type definitions, to make it readable/debuggable. */ +export type ResolveType = T extends object + ? T extends infer O + ? { [K in keyof O]: ResolveType } + : never + : T; + +/** Returns the type `true` iff X and Y are exactly equal */ +export type TypeEqual = (() => T extends X ? 1 : 2) extends () => T extends Y ? 1 : 2 + ? true + : false; + +/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ +export function assertTypeTrue() {} + +/** + * Computes the intersection of a set of types, given the union of those types. + * + * From: https://stackoverflow.com/a/56375136 + */ +export type UnionToIntersection = + /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; + +/** "Type asserts" that `X` is a subtype of `Y`. */ +type EnsureSubtype = X extends Y ? X : never; + +type TupleHeadOr = T extends readonly [infer H, ...(readonly unknown[])] ? H : Default; +type TupleTailOr = T extends readonly [unknown, ...infer Tail] ? Tail : Default; +type TypeOr = T extends undefined ? Default : T; + +/** + * Zips a key tuple type and a value tuple type together into an object. + * + * @template Keys Keys of the resulting object. + * @template Values Values of the resulting object. If a key corresponds to a `Values` member that + * is undefined or past the end, it defaults to the corresponding `Defaults` member. + * @template Defaults Default values. If a key corresponds to a `Defaults` member that is past the + * end, the default falls back to `undefined`. + */ +export type ZipKeysWithValues< + Keys extends readonly string[], + Values extends readonly unknown[], + Defaults extends readonly unknown[] +> = + // + Keys extends readonly [infer KHead, ...infer KTail] + ? { + readonly [k in EnsureSubtype]: TypeOr< + TupleHeadOr, + TupleHeadOr + >; + } & + ZipKeysWithValues< + EnsureSubtype, + TupleTailOr, + TupleTailOr + > + : {}; // K exhausted -- cgit v1.2.3