import {expectType} from 'tsd'; import type {IsWritableKeyOf} from '../source/is-writable-key-of.d.ts'; declare const never: never; declare const boolean: boolean; declare const symbol: unique symbol; // Simple object type A = { a: string; readonly b: number; c?: boolean; }; expectType>(true); expectType>(false); expectType>(true); // @ts-expect-error `d` is not in `keyof T` expectType>(false); // Index signature type B = { [k: string]: number; }; expectType>(true); // Fully readonly index type C = { readonly [k: string]: number; }; expectType>(false); expectType>(true); // Optional + readonly type D = { readonly a?: string; b: number; }; expectType>(false); expectType>(true); // Union type E1 = {a: number}; type E2 = {readonly a: number}; type E = E1 | E2; expectType>(boolean); // Intersection type F1 = {readonly a: string}; type F2 = {a: string}; type F = F1 & F2; expectType>(true); // Class instance class G { // eslint-disable-next-line @typescript-eslint/class-literal-property-style readonly x = 1; y = ''; } expectType>(false); expectType>(true); type H = { [symbol]: number; readonly x: string; }; expectType>(true); expectType>(false); // Full readonly object type I = Readonly<{ a: number; b: string; }>; expectType>(false); expectType>(false); // Object with method type J = { readonly id: string; run(): void; }; expectType>(true); expectType>(false); // Record type K = Record<'a' | 'b', string>; expectType>(true); expectType>(true); // Union of keys expectType>(boolean); expectType>(boolean); // @ts-expect-error expectType>(boolean); expectType>(true); type FullKeyUnion = keyof A; // 'a' | 'b' | 'c' expectType>(boolean); // @ts-expect-error expectType>(false); // 'x' is not in A, so filtered as false // `never` / `any type L = {readonly a: string}; expectType>(never); expectType>(never); expectType>(never); expectType>(never); expectType>(never); expectType>(never);