Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robojones/ts-nice
Some types that make your life easier when using typescript.
https://github.com/robojones/ts-nice
Last synced: 23 days ago
JSON representation
Some types that make your life easier when using typescript.
- Host: GitHub
- URL: https://github.com/robojones/ts-nice
- Owner: robojones
- License: mit
- Created: 2018-04-19T19:08:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-05-13T16:31:01.000Z (over 6 years ago)
- Last Synced: 2023-12-22T21:08:19.695Z (11 months ago)
- Language: TypeScript
- Size: 37.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ts-nice
[![CircleCI](https://circleci.com/gh/robojones/ts-nice.svg?style=svg)](https://circleci.com/gh/robojones/ts-nice)
Some types that make your life easier when using typescript.
There are three interfaces that allow you to do the following things:
- Select specific properties from a type ([Select](#select)).
- Make all properties of a type optional ([Optional](#optional)).
- Set all properties of a type to a specific type ([SetAll](#setall)).## Select
Allows you to select specific properties from an interface / type.
```typescript
import { Select } from 'ts-nice'interface Example {
a: number
b: string
}// Select only the key 'a'.
let result: Selectresult = { a: 54 } // valid
result = { a: 'asdf' } // invalid
result = { b: 'hi' } // invalid
result = {} // invalid
```You can also select multiple properties:
```typescript
interface Example {
a: number
b: string
c: boolean
}// Select the key 'a' and 'b'.
let result = Select
```## Optional
Allows you to make all properties of an interface / type optional.
```typescript
import { Optional } from 'ts-nice'interface Example { a: number, b: string }
// Make all properties optional.
let result: Optionalresult = {} // valid
result = { a: 45 } // valid
result = { a: 45, b: 'huhn' } // valid
result = { a: true } // invalid
result = { c: 'asdf' } // invalid
```## SetAll
Allows you to set all properties of an interface to a specific type.
```typescript
import { SetAll } from 'ts-nice'interface Example { a: number, b: string }
// Change the type of all properties to boolean.
let result: SetAllresult = { a: true, b: false } // valid
result = { a: 45, b: 'hi' } // invalid
result = { a: true } // invalid
```