diff --git a/README.md b/README.md index 328854b..ffc49ec 100644 --- a/README.md +++ b/README.md @@ -295,14 +295,6 @@ type Post = {title: string; content: string} expectTypeOf().readonly().toEqualTypeOf>() ``` -`.readonly` can make specific properties `readonly`: - -```typescript -type Post = {title: string; content: string} - -expectTypeOf().readonly('title').toEqualTypeOf<{readonly title: string; content: string}>() -``` - Make assertions about object properties: ```typescript diff --git a/src/index.ts b/src/index.ts index a452ebe..1818453 100644 --- a/src/index.ts +++ b/src/index.ts @@ -676,13 +676,11 @@ export interface BaseExpectTypeOf { ) => ExpectTypeOf, Options> /** - * Converts specified properties of an object to `readonly`. - * If no properties are specified, it defaults - * to making all properties `readonly`, similar to the native - * TypeScript {@linkcode Readonly} utility type. + * Converts all properties of a type to **`readonly`**, + * behaving exactly like the TypeScript {@linkcode Readonly} utility type. * * @example - * #### Make all properties `readonly` (default behavior) + * #### Create a **`readonly`** version of a type * * ```ts * import { expectTypeOf } from 'expect-type' @@ -695,35 +693,11 @@ export interface BaseExpectTypeOf { * expectTypeOf().readonly().toEqualTypeOf>() * ``` * - * @example - * #### Make specific properties `readonly` - * - * ```ts - * import { expectTypeOf } from 'expect-type' - * - * type Post = { - * title: string - * content: string - * } - * - * expectTypeOf() - * .readonly('title') - * .toEqualTypeOf<{ readonly title: string; content: string }>() - * ``` + * @returns The type with all properties made **`readonly`**, mirroring the behavior of TypeScript's {@linkcode Readonly} utility. * - * @param propertiesToMakeReadonly - The specific properties of the {@linkcode Actual} type to be made `readonly`. If omitted, all properties will be made `readonly`, behaving like the TypeScript {@linkcode Readonly} utility type. - * @returns the type with the specified properties made `readonly`. If no properties are specified, all properties will be made `readonly`, behaving like the TypeScript {@linkcode Readonly} utility. - * - * @template PropertiesToMakeReadonly - The keys of the __`Actual`__ type to be made `readonly`. Defaults to `never`, meaning no specific properties are targeted unless explicitly defined. - * - * @since 1.0.0 + * @since 1.1.0 */ - readonly( - propertiesToMakeReadonly?: PropertiesToMakeReadonly, - ): ExpectTypeOf< - IsNever extends true ? Readonly : SetReadonly, - Options - > + readonly(): ExpectTypeOf, Options> /** * Extracts a certain function argument with `.parameter(number)` call to diff --git a/src/utils.ts b/src/utils.ts index 1fe66f2..58c7c6f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -250,7 +250,7 @@ export type UnionToTuple = TuplifyUnion * expectTypeOf(undefined).not.toMatchTypeOf() * ``` * - * @since 1.0.0 + * @since 1.1.0 * @internal */ type AnyNonNullishValue = NonNullable @@ -267,7 +267,7 @@ type AnyNonNullishValue = NonNullable * const sum = ((a: number, b: number): number => a + b) satisfies AnyFunction * ``` * - * @since 1.0.0 + * @since 1.1.0 * @internal */ type AnyFunction = (...args: any[]) => any @@ -308,7 +308,7 @@ type AnyFunction = (...args: any[]) => any * }>() * ``` * - * @since 1.0.0 + * @since 1.1.0 * @internal * @see {@link https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts | Source} */ @@ -348,7 +348,7 @@ type Simplify = TypeToFlatten extends AnyFunction * @template BaseType - The base type whose properties will be transformed to `readonly`. * @template KeysToBecomeReadonly - The keys of the __`BaseType`__ to be made `readonly`. * - * @since 1.0.0 + * @since 1.1.0 */ export type SetReadonly = BaseType extends unknown ? Simplify & Readonly>> diff --git a/test/usage.test.ts b/test/usage.test.ts index 889582e..791385e 100644 --- a/test/usage.test.ts +++ b/test/usage.test.ts @@ -191,12 +191,6 @@ test('Use `.readonly` to create a `readonly` version of a type', () => { expectTypeOf().readonly().toEqualTypeOf>() }) -test('`.readonly` can make specific properties `readonly`', () => { - type Post = {title: string; content: string} - - expectTypeOf().readonly('title').toEqualTypeOf<{readonly title: string; content: string}>() -}) - test('Make assertions about object properties', () => { const obj = {a: 1, b: ''}