IF Commons GitHub

types

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-core FR-004

Tests of types with no framework (0001-core FR-004): expectType<Equal<A, B>>() compiles only where A and B are the same type, and // @ts-expect-error above a line that must not compile fails the check where that line becomes legal. They cost nothing at run time; tsc is what runs them.

import { type Equal, expectType } from "./types.ts";
expectType<Equal<ReturnType<typeof Math.max>, number>>();

Source: commons/core/src/types.ts

4 of 4 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

expectTypefunction
function expectType<_T extends true>(): void

Compiles only where its type argument is true; does nothing when run.

Imported by 16 tests of the run (16 passed, 0 failed): the library's results

Equaltype
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;

true where A and B are exactly the same type (not merely assignable either way), else false.

Imported by 16 tests of the run (16 passed, 0 failed): the library's results

Extendstype
type Extends<A, B> = [A] extends [B] ? true : false;

true where A is assignable to B.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

Nottype
type Not<T extends boolean> = T extends true ? false : true;

true where T is false: the negation of a type-level test.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.