Skip to content

Commit

Permalink
docs: modify readme and add keywords and repository to package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
kakasoo committed Jan 11, 2025
1 parent 452e040 commit eb46b26
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 22 deletions.
73 changes: 53 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,98 @@ npm i @kakasoo/deep-strict-types

# DeepStrictTypes

**DeepStrictTypes** extends TypeScript utility types, enabling safe operations like `Omit` and `Pick` on nested objects or arrays by specifying the keys to be inferred. This allows for more strict and accurate type checks.
**DeepStrictTypes** extends TypeScript utility types, enabling safe operations like `Omit` and `Pick` on nested objects or arrays by specifying the keys to be inferred. This allows for more strict and accurate type checks. **Now, you don't have to recombine numerous types daily to remove a single key from a nested object. You can quickly omit and pick the internal keys you want!**

## DeepStrictObjectKeys

`DeepStrictObjectKeys<T>` extracts all nested keys from an object `T`, preserving the structure of the nested object and returning the types of the keys. This is useful when you need to handle specific keys safely at deeper levels of an object.

```typescript
type Example = {
user: {
name: string;
address: {
city: string;
zip: number;
};
user: {
name: string;
address: {
city: string;
zip: number;
};
};
};

// Result: "user" | "user.name" | "user.address" | "user.address.city" | "user.address.zip"
type Keys = DeepStrictObjectKeys<Example>;
```

In the case of an array, the inside is represented by the `[*]` symbol. Of course, the arrangement of the array, the arrangement of objects in the array, and even if the top object is an array, it is perfectly inferred.

## DeepStrictOmit

DeepStrictOmit<T, K> creates a new type by excluding properties corresponding to the key K from object T, while preserving the nested structure. This type allows precise omission of keys even in deeply nested objects.
`DeepStrictOmit<T, K>` creates a new type by excluding properties corresponding to the key K from object T, while preserving the nested structure. This type allows precise omission of keys even in deeply nested objects.

```ts
type Example = {
user: {
name: string;
age: number;
};
user: {
name: string;
age: number;
};
};

// Result: { user: { age: number; } }
type Omitted = DeepStrictOmit<Example, "user.name">;
type Omitted = DeepStrictOmit<Example, 'user.name'>;
```

This is also useful for branding types. Below is an example of defining a branding type using a library called typia, in which DeepStrictOmit can also be safely used.

```ts
test('TEST 1. apply DeepStrictOmit to primitive property type of branding type', () => {
type TestInterface = {
id: string;
title: string;
thumbnails: {
name: null | (string & MinLength<1> & MaxLength<255>);
extension: null | (string & MinLength<1> & MaxLength<8>);
url: string;
}[];
};

type Question = DeepStrictOmit<TestInterface, 'id'>;
type IsAnswer = Equal<
Question,
{
title: string;
thumbnails: {
name: null | (string & MinLength<1> & MaxLength<255>);
extension: null | (string & MinLength<1> & MaxLength<8>);
url: string;
}[];
}
>;

ok(typia.random<IsAnswer>());
});
```

## DeepStrictPick

DeepStrictPick<T, K> creates a new type by selecting only the properties corresponding to the key K from object T, while preserving the nested structure. It allows safely selecting specific keys even from deep objects.
`DeepStrictPick<T, K>` creates a new type by selecting only the properties corresponding to the key K from object T, while preserving the nested structure. It allows safely selecting specific keys even from deep objects.

```ts
type Example = {
user: {
name: string;
age: number;
};
user: {
name: string;
age: number;
};
};

// Result: { user: { name: string; } }
type Picked = DeepStrictPick<Example, "user.name">;
type Picked = DeepStrictPick<Example, 'user.name'>;
```

## DeepStrictUnbrand

DeepStrictUnbrand<T> removes branding from type T and applies it even to deeply nested objects. This makes handling complex branded types simpler by removing the branding for more straightforward use.

```ts
type BrandedType = { brand: number & { type: "won" } };
type BrandedType = { brand: number & { type: 'won' } };

// Result: { value: number; }
type Unbranded = DeepStrictUnbrand<BrandedType>;
Expand Down
33 changes: 31 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,33 @@
"test": "node bin/test/index.js",
"prettier": "prettier src --write && prettier test --write"
},
"keywords": [],
"author": "",
"keywords": [
"typescript",
"types",
"utility-types",
"deep-types",
"nested-types",
"type-safety",
"type-checking",
"strict-types",
"deep-strict",
"deep-pick",
"deep-omit",
"deep-keys",
"deep-object",
"type-utils",
"type-helpers",
"typescript-utils",
"typescript-types",
"type-manipulation",
"nested-objects",
"object-types",
"array-types",
"type-inference",
"type-assertions",
"type-validation"
],
"author": "kakasoo",
"license": "ISC",
"devDependencies": {
"@samchon/shopping-api": "^0.12.1",
Expand All @@ -30,6 +55,10 @@
"typescript": "^5.7.2",
"typia": "^7.5.1"
},
"repository": {
"type": "git",
"url": "https://github.com/kakasoo/deepstricttypes"
},
"dependencies": {
"@kakasoo/proto-typescript": "^1.28.7"
}
Expand Down

0 comments on commit eb46b26

Please sign in to comment.