From a2491e5cff6e95a90a7db0420a1626e6293fb07a Mon Sep 17 00:00:00 2001 From: raon0211 Date: Fri, 9 Aug 2024 10:08:21 +0900 Subject: [PATCH] fix(isObjectLike): Make the docs more intuitive --- docs/ko/reference/predicate/isObjectLike.md | 12 ++++++------ docs/reference/predicate/isObjectLike.md | 10 +++++----- docs/zh_hans/reference/predicate/isObjectLike.md | 12 ++++++------ src/predicate/isObjectLike.ts | 11 +++++------ 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/docs/ko/reference/predicate/isObjectLike.md b/docs/ko/reference/predicate/isObjectLike.md index 27a75898..17bdd707 100644 --- a/docs/ko/reference/predicate/isObjectLike.md +++ b/docs/ko/reference/predicate/isObjectLike.md @@ -1,24 +1,24 @@ # isObjectLike -주어진 값이 유사 객체인지 확인해요. +주어진 값이 객체 같은지 확인해요. -만약 주어진 값이 유사 객체이면 `true`, 아니면 `false`를 반환해요. +객체 같은 값이란, `typeof` 연산의 결과가 `'object'` 이고 `null`이 아닌 값을 말해요. -TypeScript의 타입 가드로 사용할 수 있어요. 파라미터로 주어진 값의 타입을 유사 객체로 좁혀요. +TypeScript의 타입 가드로 사용할 수 있어요. 파라미터로 주어진 값의 타입을 객체 같은 값으로 좁혀요. ## 인터페이스 ```typescript -export function isObjectLike(value: T): value is Extract; +export function isObjectLike(value: unknown): value is object; ``` ### 파라미터 -- `value` (`T`): 유사 객체인지 확인할 값이에요. +- `value` (`T`): 객체 같은지 확인할 값이에요. ### 반환 값 -(`value is Extract`): 주어진 값이 유사 객체이면 `true`, 아니면 `false`를 반환해요. +(`value is object`): 주어진 값이 객체 같으면 `true`, 아니면 `false`를 반환해요. ## 예시 diff --git a/docs/reference/predicate/isObjectLike.md b/docs/reference/predicate/isObjectLike.md index 60713334..a88ae226 100644 --- a/docs/reference/predicate/isObjectLike.md +++ b/docs/reference/predicate/isObjectLike.md @@ -2,23 +2,23 @@ Check if a value is an object-like. -It returns `true` if the value is an object-like, and `false` otherwise. +A value is object-like if its type is object and it is not null. -This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object-like. +This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object-like value. ## Signature ```typescript -export function isObjectLike(value: T): value is Extract; +function isObjectLike(value: unknown): value is object; ``` ### Parameters -- `value` (`T`): The value to test if it is an object-like. +- `value` (`unknown`): The value to test if it is an object-like. ### Returns -(`value is Extract`): Returns `true` if the value is an object-like, `false` otherwise. +(`value is object`): Returns `true` if the value is an object-like, `false` otherwise. ## Examples diff --git a/docs/zh_hans/reference/predicate/isObjectLike.md b/docs/zh_hans/reference/predicate/isObjectLike.md index 2db408f3..96d51d1f 100644 --- a/docs/zh_hans/reference/predicate/isObjectLike.md +++ b/docs/zh_hans/reference/predicate/isObjectLike.md @@ -1,24 +1,24 @@ # isObjectLike -检查一个值是否是类对象。 +检查一个值是否类似对象。 -如果该值是类对象,则返回 `true`,否则返回 `false`。 +如果一个值的类型是对象并且它不为 `null`,那么它就是类似对象的。 -这个函数也可以在 TypeScript 中作为类型断言使用,将参数的类型缩小为类对象。 +这个函数还可以在 TypeScript 中用作类型谓词,将参数的类型缩小到类似对象的值。 ## 签名 ```typescript -export function isObjectLike(value: T): value is Extract; +function isObjectLike(value: unknown): value is object; ``` ### 参数 -- `value` (`T`): 要检查是否为类对象的值。 +- `value` (`unknown`): 要检查是否为类对象的值。 ### 返回值 -(`value is Extract`): 如果该值是类对象,则返回 `true`,否则返回 `false`。 +(`value is object`): 如果该值是类对象,则返回 `true`,否则返回 `false`。 ## 示例 diff --git a/src/predicate/isObjectLike.ts b/src/predicate/isObjectLike.ts index 2f105435..019ae82a 100644 --- a/src/predicate/isObjectLike.ts +++ b/src/predicate/isObjectLike.ts @@ -1,10 +1,9 @@ /** - * Checks if the given value is an object-like. + * Checks if the given value is object-like. + * + * A value is object-like if its type is object and it is not null. * - * This function tests whether the provided value is an object-like or not. - * It returns `true` if the value is an object-like, and `false` otherwise. - * - * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object-like. + * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object-like value. * * @template T - The type of value. * @param {T} value - The value to test if it is an object-like. @@ -23,6 +22,6 @@ * console.log(isObjectLike(value4)); // false */ -export function isObjectLike(value: T): value is Extract { +export function isObjectLike(value: unknown): value is object { return typeof value === 'object' && value !== null; }