Skip to content

Commit

Permalink
Merge pull request #6 from oshx/chore/readme
Browse files Browse the repository at this point in the history
Modified examples with 'typeof' operator.
Updated a version.
Split the code blocks in README.md.
  • Loading branch information
oshx authored Jul 3, 2024
2 parents 88208a4 + caf18be commit 1ce750a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@ Please add below in `tsconfig.json` file.

```typescript
type ObjectKey
// explicit constant object keys
// explicit constant object keys
```

```typescript
type ObjectValue
// explicit constant object values
// explicit constant object values
```

```typescript
type PropsWithClassName
// extendable interface-like-type with optional property 'className'
// extendable interface-like-type with optional property 'className'
```

```typescript
type AnyFunction
// simply declared any function
// simply declared any function
```

## Why it comes for?
Expand Down Expand Up @@ -78,6 +84,7 @@ export const ObjectA = {
KEY_A: 'valueA',
KEY_B: 'valueB',
} as const;
// Same effects with Enum type!
export type ObjectAKey = ObjectKey<typeof ObjectA>;
export type ObjectAValue = ObjectValue<typeof ObjectA>;
Expand All @@ -86,7 +93,7 @@ export type ObjectAValue = ObjectValue<typeof ObjectA>;
const shouldBeKeyOfA: ObjectAKey = 'KeyA';
const shouldBeValueOfA: ObjectAValue = 'ValueA';
// Passed!
// Passed ✔️
const keyOfA: ObjectAKey = 'KEY_A';
const valueOfA: ObjectAValue = 'valueA';
```
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* KEY_B: 'valueB',
* } as const;
*
* type ObjectKey<ObjectA> = 'KEY_A'|'KEY_B';
* type ObjectKey<typeof ObjectA> = 'KEY_A'|'KEY_B';
*/

declare type ObjectKey<T extends object = any> = keyof T
Expand All @@ -19,7 +19,7 @@ declare type ObjectKey<T extends object = any> = keyof T
* KEY_B: 'valueB',
* } as const;
*
* type ObjectValue<ObjectA> = 'valueA'|'valueB';
* type ObjectValue<typeof ObjectA> = 'valueA'|'valueB';
*/
declare type ObjectValue<T extends object = any> = T[ObjectKey<T>]

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oshx/type-helper",
"version": "1.0.4",
"version": "1.0.5",
"description": "Types help TypeScript types.",
"repository": {
"type": "git",
Expand Down

0 comments on commit 1ce750a

Please sign in to comment.