Skip to content
This repository was archived by the owner on Feb 16, 2021. It is now read-only.

Commit 397461d

Browse files
authored
add Required, Purify, NonNullable, closes #15 (#16)
1 parent c687af1 commit 397461d

File tree

6 files changed

+67
-39
lines changed

6 files changed

+67
-39
lines changed

CHANGELOG.md

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,49 @@
11
# Changelog
22

33
> **Tags:**
4-
> - [New Feature]
5-
> - [Bug Fix]
6-
> - [Breaking Change]
7-
> - [Documentation]
8-
> - [Internal]
9-
> - [Polish]
10-
> - [Experimental]
4+
>
5+
> * [New Feature]
6+
> * [Bug Fix]
7+
> * [Breaking Change]
8+
> * [Documentation]
9+
> * [Internal]
10+
> * [Polish]
11+
> * [Experimental]
1112
12-
**Note**: Gaps between patch versions are faulty/broken releases.
13-
**Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.
13+
**Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a
14+
high state of flux, you're at risk of it changing without notice.
15+
16+
# 0.2.2
17+
18+
* **New Feature**
19+
* add `Required`, `Purify`, `NonNullable`, closes #15 (@gcanti)
1420

1521
# 0.2.1
1622

17-
- **New Feature**
18-
- add `ObjectOptional`, closes #13 (@thepheer)
23+
* **New Feature**
24+
* add `ObjectOptional`, closes #13 (@thepheer)
1925

2026
# 0.2.0
2127

22-
- **Breaking Change**
23-
- complete refactoring
24-
- upgrade to TypeScript 2.5.2 (@gcanti)
28+
* **Breaking Change**
29+
* complete refactoring
30+
* upgrade to TypeScript 2.5.2 (@gcanti)
2531

2632
# 0.1.3
2733

28-
- **New Feature**
29-
- `NumberToNat`
30-
- `NatToNumber`
31-
- hlists
32-
- tuples
33-
- convert tuples to / from hlists (`TupleToTHList`, `THListToTuple`)
34+
* **New Feature**
35+
* `NumberToNat`
36+
* `NatToNumber`
37+
* hlists
38+
* tuples
39+
* convert tuples to / from hlists (`TupleToTHList`, `THListToTuple`)
3440

3541
# 0.1.2
3642

37-
- **Bug Fix**
38-
- remove `ObjectExact` (@gcanti)
43+
* **Bug Fix**
44+
* remove `ObjectExact` (@gcanti)
3945

4046
# 0.1.1
4147

42-
- **New Feature**
43-
- `PickExact` (@gcanti)
48+
* **New Feature**
49+
* `PickExact` (@gcanti)

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# Compatibility
22

3-
- `0.2.0+` for TypeScript `2.5.2+`
4-
- `0.1.3` for TypeScript `2.4.1+`
3+
* `0.2.0+` for TypeScript `2.5.2+`
4+
* `0.1.3` for TypeScript `2.4.1+`
55

66
# Credits
77

88
Adapted from
99

10-
- https://github.com/Microsoft/TypeScript/issues/14833
11-
- https://github.com/Microsoft/TypeScript/issues/16392
12-
- https://github.com/Microsoft/TypeScript/issues/12215
10+
* https://github.com/Microsoft/TypeScript/issues/14833
11+
* https://github.com/Microsoft/TypeScript/issues/16392
12+
* https://github.com/Microsoft/TypeScript/issues/12215
1313

1414
## Related projects
1515

16-
- [typical - playground for type-level primitives in TypeScript](https://github.com/tycho01/typical) by @tycho01
16+
* [typical - playground for type-level primitives in TypeScript](https://github.com/tycho01/typical) by @tycho01
1717

1818
# Examples
1919

@@ -95,4 +95,3 @@ class Foo extends React.Component<{ bar: string; baz: number }> {}
9595
const FilledFoo = withProps(Foo, { baz: 1 })
9696
const x = <FilledFoo bar="bar" /> // ok
9797
```
98-

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22
"name": "typelevel-ts",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "Type level programming in TypeScript",
55
"files": ["lib"],
66
"main": "lib/index.js",
77
"typings": "lib/index.d.ts",
88
"scripts": {
99
"lint": "tslint src/**/*.ts",
10-
"typings-checker": "typings-checker --allow-expect-error --project typings-checker/tsconfig.json typings-checker/index.ts",
11-
"prettier": "prettier --no-semi --single-quote --print-width 120 --parser typescript --list-different \"{src,typings-checker}/**/*.ts\"",
10+
"typings-checker":
11+
"typings-checker --allow-expect-error --project typings-checker/tsconfig.json typings-checker/index.ts",
12+
"prettier":
13+
"prettier --no-semi --single-quote --print-width 120 --parser typescript --list-different \"{src,typings-checker}/**/*.ts\"",
1214
"test": "npm run prettier && npm run lint && npm run typings-checker",
1315
"clean": "rm -rf lib/*",
1416
"build": "npm run clean && tsc"
@@ -25,10 +27,10 @@
2527
"homepage": "https://github.com/gcanti/typelevel-ts",
2628
"dependencies": {},
2729
"devDependencies": {
28-
"prettier": "1.5.2",
30+
"prettier": "1.8.2",
2931
"tslint": "4.4.2",
3032
"tslint-config-standard": "4.0.0",
31-
"typescript": "2.6.0-rc",
33+
"typescript": "2.6.1",
3234
"typings-checker": "1.1.2"
3335
},
3436
"tags": [],

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ export type ObjectOptional<O, K extends keyof O> = ObjectOmit<O, K> & Partial<Pi
176176

177177
export type PickExact<O, K extends keyof O> = Pick<O, K> & { [K1 in StringOmit<keyof O, K>]?: never }
178178

179+
export type Required<T> = { [P in Purify<keyof T>]: NonNullable<T[P]> }
180+
181+
export type Purify<T extends string> = { [P in T]: T }[T]
182+
183+
export type NonNullable<T> = T & {}
184+
179185
//
180186
// hlists
181187
//

typings-checker/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,20 @@ const natToString0: t.NatToString<t.Zero> = '0'
139139
const natToString1: t.NatToString<t.One> = '1'
140140
const natToString2: t.NatToString<t.Two> = '2'
141141
const natToString10: t.NatToString<t.Ten> = '10'
142+
143+
//
144+
// Required
145+
//
146+
type R1 = {
147+
a: string
148+
b?: number
149+
c?: boolean | null | undefined
150+
}
151+
type RR1 = t.Required<R1>
152+
// $ExpectError Property 'a' is missing in type '{}'
153+
const r1: RR1 = {}
154+
// $ExpectError Property 'b' is missing in type '{ a: string; }'
155+
const r2: RR1 = { a: 'a' }
156+
// $ExpectError Property 'c' is missing in type '{ a: string; b: number; }'
157+
const r3: RR1 = { a: 'a', b: 1 }
158+
const r4: RR1 = { a: 'a', b: 1, c: true }

typings-checker/tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@
1010
"strictNullChecks": true,
1111
"target": "es5"
1212
},
13-
"lib": [
14-
"es6", "dom"
15-
]
13+
"lib": ["es6", "dom"]
1614
}

0 commit comments

Comments
 (0)