-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: @modern-kit/types * docs: modern-kit/types document 추가 * chore: types package.json
- Loading branch information
Showing
28 changed files
with
391 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-2.6 MB
.yarn/cache/@rollup-rollup-linux-x64-gnu-npm-4.14.3-ca0d385d25-10c0.zip
Binary file not shown.
Binary file removed
BIN
-2.68 MB
.yarn/cache/@rollup-rollup-linux-x64-gnu-npm-4.15.0-dea17bae79-10c0.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
*.log | ||
npm-debug.log* | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
.nyc_output | ||
|
||
# Dependency directories | ||
node_modules | ||
|
||
# npm package lock | ||
package-lock.json | ||
yarn.lock | ||
|
||
# project files | ||
src | ||
|
||
# git | ||
.gitignore | ||
|
||
# setting | ||
tsconfig.json | ||
tsconfig.paths.json | ||
.prettierrc | ||
.eslintrc.js | ||
webpack.*.js | ||
babel.config.js | ||
rollup.config.mjs | ||
|
||
# test | ||
coverage | ||
vite.config.ts | ||
vite.setup.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# @modern-kit/utils <a href="https://www.npmjs.com/package/@modern-kit/utils" target="_blank"><img align="center" src="https://img.shields.io/npm/v/@modern-kit/utils.svg" /></a> <a href="https://bundlephobia.com/package/@modern-kit/utils" target="_blank"><img align="center" src="https://img.shields.io/bundlephobia/minzip/@modern-kit/utils/latest"></a> | ||
|
||
유용한 타입스크립트 유틸 타입들을 제공합니다. | ||
|
||
<br /> | ||
|
||
## Documentation | ||
`@modern-kit`의 공식 문서는 아래 웹사이트에서 확인하실 수 있습니다 | ||
- <a href="https://modern-agile-team.github.io/modern-kit" target="_blank">https://modern-agile-team.github.io/modern-kit</a> | ||
|
||
<br /> | ||
|
||
## Usage | ||
```shell | ||
npm i @modern-kit/types | ||
``` | ||
|
||
```shell | ||
yarn add @modern-kit/types | ||
``` | ||
|
||
|
||
```shell | ||
pnpm i @modern-kit/types | ||
``` | ||
|
||
<br /> | ||
|
||
## License | ||
MIT © Modern Agile. See [LICENSE](../../LICENSE) for details. | ||
|
||
<br /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "@modern-kit/types", | ||
"sideEffects": false, | ||
"version": "1.0.0", | ||
"description": "modern-kit/types", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"test": "vitest", | ||
"test:run": "vitest run", | ||
"typecheck": "tsc", | ||
"build": "rm -rf dist && yarn typecheck" | ||
}, | ||
"author": "ssi02014 <ssi02014@naver.com>", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"devDependencies": { | ||
"tslib": "^2.6.2", | ||
"typescript": "^5.1.6", | ||
"vitest": "^1.5.0" | ||
}, | ||
"keywords": [ | ||
"react", | ||
"next", | ||
"utils", | ||
"component", | ||
"ui", | ||
"hooks", | ||
"custom hooks" | ||
], | ||
"gitHead": "7722785374b897572934e335817ec297ad45a943" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { describe, expectTypeOf, it } from 'vitest'; | ||
import { Arrayable } from '.'; | ||
|
||
describe('Nullable', () => { | ||
it('제네릭 타입으로 넣어준 원시 타입과 해당 원시 타입으로 이뤄진 배열을 허용합니다.', () => { | ||
const test = ['123'] as Arrayable<string>; | ||
|
||
expectTypeOf(test).toEqualTypeOf<string | string[]>(); | ||
}); | ||
|
||
it('조건식으로 원시 타입, 배열 타입 각각 타입을 좁힐 수 있습니다.', () => { | ||
const test = ['123'] as Arrayable<string>; | ||
|
||
if (Array.isArray(test)) { | ||
expectTypeOf(test).toEqualTypeOf<string[]>(); | ||
} else { | ||
expectTypeOf(test).toEqualTypeOf<string>(); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type Arrayable<T> = T | Array<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { describe, expectTypeOf, it } from 'vitest'; | ||
import { ExcludeNullish } from '.'; | ||
|
||
describe('ExcludeNullish', () => { | ||
it('제네릭으로 넣어준 타입에서 null과 undefined를 제외합니다.', () => { | ||
const test = '123' as ExcludeNullish<string | null | undefined>; | ||
|
||
expectTypeOf(test).toEqualTypeOf<string>(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type ExcludeNullish<T> = Exclude<T, null | undefined>; |
19 changes: 19 additions & 0 deletions
19
packages/types/src/ExtendOmittedProperties/ExtendOmittedProperties.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { describe, expectTypeOf, it } from 'vitest'; | ||
import { ExtendOmittedProperties } from '.'; | ||
|
||
describe('ExcludeNullish', () => { | ||
it('첫 번째 제네릭 타입의 프로퍼티를 Omit으로 제외 후 제외 한 프로퍼티를 확장합니다.', () => { | ||
type TestType = { foo: string; bar: number }; | ||
|
||
const test: ExtendOmittedProperties<TestType, { bar: string }> = { | ||
foo: 'foo', | ||
bar: 'bar', | ||
}; | ||
|
||
// toEqualTypeOf 이슈로 우회 테스트 | ||
expectTypeOf(test as { foo: string; bar: string }).toEqualTypeOf<{ | ||
foo: string; | ||
bar: string; | ||
}>(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type ExtendOmittedProperties< | ||
T extends Record<PropertyKey, any>, | ||
E extends Record<PropertyKey, any> | ||
> = Omit<T, keyof E> & E; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { describe, expectTypeOf, it } from 'vitest'; | ||
import { IndexSignature } from '.'; | ||
|
||
describe('IndexSignature', () => { | ||
it('객체가 가질 수 있는 프로퍼티를 동적으로 추가할 수 있게 허용합니다. value의 타입은 제네릭으로 넣어준 타입입니다.', () => { | ||
const test: IndexSignature<string> = { foo: 'foo', bar: 'bar' }; | ||
test.test = '1'; | ||
|
||
expectTypeOf(test).toEqualTypeOf<{ [key: PropertyKey]: string }>(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type IndexSignature<T> = { | ||
[key: PropertyKey]: T; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { describe, expectTypeOf, it } from 'vitest'; | ||
import { Nullable } from '.'; | ||
|
||
describe('Nullable', () => { | ||
it('제네릭 타입으로 넣어준 타입과 더불어 null과 undefined를 허용합니다.', () => { | ||
const test = '123' as Nullable<string>; | ||
|
||
expectTypeOf(test).toEqualTypeOf<string | null | undefined>(); | ||
}); | ||
|
||
it('조건식으로 타입을 좁히면 제네릭 타입으로 좁혀집니다.', () => { | ||
const test = '123' as Nullable<string>; | ||
|
||
if (test) { | ||
expectTypeOf(test).toEqualTypeOf<string>(); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type Nullable<T> = T | null | undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { describe, expectTypeOf, it } from 'vitest'; | ||
import { ObjectEntries } from '.'; | ||
|
||
describe('ObjectKeys', () => { | ||
it('Object.entries의 반환 타입을 명확하게 합니다. symbol은 제외합니다.', () => { | ||
const test = { | ||
foo: 'foo', | ||
bar: 'bar', | ||
} as const; | ||
|
||
const defaultEntries = Object.entries(test); | ||
const AppliedEntries = Object.entries(test) as ObjectEntries<typeof test>; | ||
|
||
expectTypeOf(defaultEntries).toEqualTypeOf<[string, 'foo' | 'bar'][]>(); | ||
expectTypeOf(AppliedEntries).toEqualTypeOf< | ||
['foo' | 'bar', 'foo' | 'bar'][] | ||
>(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ObjectKeys } from '../ObjectKeys'; | ||
|
||
export type ObjectEntries<T extends Record<PropertyKey, T[keyof T]>> = [ | ||
ObjectKeys<T>, | ||
T[ObjectKeys<T>] | ||
][]; |
Oops, something went wrong.