fix(isObjectLike): Make the docs more intuitive

This commit is contained in:
raon0211 2024-08-09 10:08:21 +09:00
parent 05938e0c1d
commit a2491e5cff
4 changed files with 22 additions and 23 deletions

View File

@ -1,24 +1,24 @@
# isObjectLike
주어진 값이 유사 객체인지 확인해요.
주어진 값이 객체 같은지 확인해요.
만약 주어진 값이 유사 객체이면 `true`, 아니면 `false`를 반환해요.
객체 같은 값이란, `typeof` 연산의 결과가 `'object'` 이고 `null`이 아닌 값을 말해요.
TypeScript의 타입 가드로 사용할 수 있어요. 파라미터로 주어진 값의 타입을 유사 객체로 좁혀요.
TypeScript의 타입 가드로 사용할 수 있어요. 파라미터로 주어진 값의 타입을 객체 같은 값으로 좁혀요.
## 인터페이스
```typescript
export function isObjectLike<T>(value: T): value is Extract<T, object>;
export function isObjectLike(value: unknown): value is object;
```
### 파라미터
- `value` (`T`): 유사 객체인지 확인할 값이에요.
- `value` (`T`): 객체 같은지 확인할 값이에요.
### 반환 값
(`value is Extract<T, object>`): 주어진 값이 유사 객체이`true`, 아니면 `false`를 반환해요.
(`value is object`): 주어진 값이 객체 같으`true`, 아니면 `false`를 반환해요.
## 예시

View File

@ -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<T>(value: T): value is Extract<T, object>;
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<T, object>`): 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

View File

@ -1,24 +1,24 @@
# isObjectLike
检查一个值是否类对象。
检查一个值是否类对象。
如果该值是类对象,则返回 `true`,否则返回 `false`
如果一个值的类型是对象并且它不为 `null`,那么它就是类似对象的
这个函数也可以在 TypeScript 中作为类型断言使用,将参数的类型缩小为类对象
这个函数还可以在 TypeScript 中用作类型谓词,将参数的类型缩小到类似对象的值
## 签名
```typescript
export function isObjectLike<T>(value: T): value is Extract<T, object>;
function isObjectLike(value: unknown): value is object;
```
### 参数
- `value` (`T`): 要检查是否为类对象的值。
- `value` (`unknown`): 要检查是否为类对象的值。
### 返回值
(`value is Extract<T, object>`): 如果该值是类对象,则返回 `true`,否则返回 `false`
(`value is object`): 如果该值是类对象,则返回 `true`,否则返回 `false`
## 示例

View File

@ -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<T>(value: T): value is Extract<T, object> {
export function isObjectLike(value: unknown): value is object {
return typeof value === 'object' && value !== null;
}