Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

TypeScript · 20 lines · 1.2 KiB · at 9c48a39

// Each line ending in an `expect` marker must be reported with that code, and nothing else in// this example may be reported. Option, null, casts and the other escape hatches.import type { Option } from "@tsus/v2";export const firstUpper = (parts: readonly string[]): string => parts[0].toUpperCase(); // expect TSUS500export const nothing = (): string | null => null; // expect TSUS502 TSUS502export const label = (name: Option<string>): string => (name ? name : "anonymous"); // expect TSUS503export const retries = (n: Option<number>): number => n || 3; // expect TSUS503export const forced = (xs: readonly number[]): number => xs[0]!; // expect TSUS507export const loose = (raw: string): any => JSON.parse(raw); // expect TSUS508export const narrowed = (raw: unknown): string => raw as string; // expect TSUS506// @ts-expect-error -- expect TSUS509export const wrong: number = "4";// Comparing a library's null is fine; so are truthiness tests on objects and booleans.export const found = (re: RegExp, s: string): Option<string> => {  const m = re.exec(s);  return m === null ? undefined : m[0];};export const flag = (on: Option<boolean>): string => (on ? "on" : "off");