Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Primitive and Falsey #70

Merged
merged 1 commit into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ Issues can be funded by anyone and the money will be transparently distributed t

# Table of Contents

## Aliases

* [`Primitive`](#primitive)
* [`Falsey`](#falsey)

## Operations on sets

* [`SetIntersection<A, B>`](#setintersectiona-b-same-as-extract)
Expand Down Expand Up @@ -209,6 +214,22 @@ Extract subset `B` from set `A`

---

## Aliases

### `Primitive`

The primitive types in TypeScript

[⇧ back to top](#aliases)

### `Falsey`

The falsey values in TypeScript, except NaN which cannot be represented as a type literal

[⇧ back to top](#aliases)

---

## Operations on objects

### `FunctionKeys<T>`
Expand Down
28 changes: 21 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/__snapshots__/mapped-types.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ exports[`DeepRequired testType<ReturnType<DeepRequired<NestedFunctionProps>['fir

exports[`Diff testType<Diff<Props, NewProps>>() 1`] = `"Pick<Props, \\"name\\" | \\"visible\\">"`;

exports[`Falsey testType<Falsey>() 1`] = `"Falsey"`;

exports[`FunctionKeys testType<FunctionKeys<MixedProps>>() 1`] = `"\\"setName\\""`;

exports[`Intersection testType<Intersection<Props | NewProps, DefaultProps>>() 1`] = `"Pick<Props, \\"age\\"> | Pick<NewProps, \\"age\\">"`;
Expand All @@ -104,6 +106,8 @@ exports[`Overwrite testType<Overwrite<Props, NewProps>>() 1`] = `"Pick<Pick<Prop

exports[`PickByValue testType<PickByValue<Props, string | number>>() 1`] = `"Pick<Props, \\"name\\" | \\"age\\">"`;

exports[`Primitive testType<Primitive>() 1`] = `"Primitive"`;

exports[`PromiseType testType<PromiseType<Promise<string>>>() 1`] = `"string"`;

exports[`ReadonlyKeys testType<ReadonlyKeys<ReadWriteProps>>() 1`] = `"\\"a\\""`;
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ export {
DeepNonNullable,
DeepPartial,
Diff,
Falsey,
FunctionKeys,
Intersection,
NonFunctionKeys,
NonUndefined,
Omit,
Overwrite,
Primitive,
PromiseType,
SetComplement,
SetDifference,
Expand Down
14 changes: 14 additions & 0 deletions src/mapped-types.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { testType } from '../utils/test-utils';
import {
Primitive,
Falsey,
SetIntersection,
SetDifference,
SetComplement,
Expand Down Expand Up @@ -48,6 +50,18 @@ type ReadWriteProps = { readonly a: number; b: string };
* Tests
*/

// @dts-jest:group Primitive
it('Primitive', () => {
// @dts-jest:pass:snap
testType<Primitive>();
});

// @dts-jest:group Falsey
it('Falsey', () => {
// @dts-jest:pass:snap
testType<Falsey>();
});

// @dts-jest:group SetIntersection
it('SetIntersection', () => {
// @dts-jest:pass:snap
Expand Down
20 changes: 19 additions & 1 deletion src/mapped-types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
/**
* Credits to all the people who given inspiration and shared some very usefull code snippets
* Credits to all the people who given inspiration and shared some very useful code snippets
* in the following github issue: https:/Microsoft/TypeScript/issues/12215
*/

/**
* Primitive
* @desc The primitive types in TypeScript
* @example
* // Expect: object
* // type ResultStripPrimitives = Exclude<string | object, Primitive>
*/
export type Primitive = number | boolean | string | symbol;

/**
* Falsey
* @desc The falsey values in TypeScript, except NaN
* @example
* // Expect: "a" | "b"
* // type ResultCompact = Exclude<'a' | 'b' | undefined | false, Falsey>;
*/
export type Falsey = null | undefined | false | 0 | '';

/**
* SetIntersection (same as Extract)
* @desc Set intersection of given union types `A` and `B`
Expand Down