# 0type

> ts类型包

Latest version **0.2.0** (published 2024-12-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install 0type
pnpm add 0type
yarn add 0type
bun add 0type
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2024-12-27 |
| First published | 2023-11-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ruihuag |
| Maintainers | ruihuag |
| Keywords | typescript, ts, type |

## Links

- npm: https://www.npmjs.com/package/0type
- npm.io page: https://npm.io/package/0type

## Alternatives

- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads
- [@1selfworld/adchain-sdk-react-native](https://npm.io/package/@1selfworld/adchain-sdk-react-native.md) — 80 weekly downloads

## Recent versions

- 0.2.0 (latest) — 2024-12-27
- 0.1.0 — 2024-04-07
- 0.0.3 — 2024-04-07
- 0.0.2 — 2024-04-07
- 0.0.1 — 2023-11-28

## README

# 描述

## ts 内置常用 & 拓展

- 拓展内置类型名前加`E`, 表示对原有的类型进行拓展

### `Record<K, T>`

- 生成属性为`K`, 类型为`T`的类型几何
- `K` 只支持 `number`, `string` , `symbol` 的类型

```ts
 const t1: Record<'s' |  -1 | symbol, number> = {
  's': 123,
  '-1': 123,
  [Symbol(1)]: 123
 }

```

#### `ERcord<K, T>`

- 拓展`K`的支持类型 `null, undefined, boolean`

```ts
 const te1: ERecord<null | undefined| true | false | '12', 1> = {
  null: 1,
  undefined: 1,
  false: 1,
  true: 1,
  12: 1
 }
```

### `Partial<T>`

- 全部变可选

```ts
 type tt = {
  a: number,
  b: number
 }

 const t2: Partial<tt> = {}
```

### `Required<T>`

- 全部变必填

```ts
 type tt = {
  a?: number,
  b: number
 }

 const t3: Required<tt> = {
  a: 0,
  b: 0
 }
```

### `Readonly<T>`

- 全部变只读

```ts
 type tt = {
  a: number,
  b: number
 }
 type t1 = Readonly<tt>
 // 等同于
 type t2 = {
  readonly a: number;
  readonly b: number;
 }
```

### `Pick<T,K>`

- 提取指定属性

```ts
 type tt = {
  n: number,
  n2: number,
  s: string,
  s2: string,
 }
 const t1: Pick<tt, 'n'> = {
  n: 1
 }
 const t2: Pick<tt, 'n'|'s'> = {
  n: 1,
  s: 's'
 }
```

### `Exclude<T,U>`

- 从`T`中排除掉所有包含`U`的属性

```ts
 type tt = number | string | boolean
 const t1: Exclude<tt, number|string> =  true
 const t2: Exclude<tt, number|boolean> = '12'
```

### `Extact<T,U>`

- 提取T和U都有的

```ts
 type tt = number | string | boolean
 const t1: Extract<tt, number> =  12
 const t2: Extract<tt, boolean> = true
```

### `NonNullable<T>`

- 去除掉`null`和`underfined`

```ts
// 不可以为 null 和 undefined
const t1: NonNullable<number> = 1
const t2: NonNullable<123> = 123
```

### `Omit<T,K>`

- 忽略T中的K属性

## 基础类型

| 类型             | 描述               | 预期                                                                     |
| :--------------- | :----------------- | :----------------------------------------------------------------------- |
| `NumberLike`     | 可转`number`的类型 | <code> number \| \`${number}\` </code>                                   |
| `CanStringified` | 可转`string`的类型 | <code>string \| number \| bigint \| boolean \| null \| undefined </code> |

## ts拓展

---
_Source: https://npm.io/package/0type · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
