Skip to content

Commit

Permalink
Add mixed type (#81)
Browse files Browse the repository at this point in the history
* Add mixed type

* Add mixed to TOC

* Add mixed test

* Run Prettier

* Update snapshots

* Update mixed description

* Add link for mixed docs

* Move mixed to Utility types section

* Add missing spaces
  • Loading branch information
goodmind authored and piotrwitek committed May 7, 2019
1 parent caf9b6c commit 8de38fe
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Issues can be funded by anyone and the money will be transparently distributed t
* [`$Shape<T>`](#shapet)
* [`$NonMaybeType<T>`](#nonmaybetypet)
* [`Class<T>`](#classt)
* [`mixed`](#mixed)

## Deprecated API (use at own risk)
* `getReturnOfExpression()` - from TS v2.0 it's better to use type-level `ReturnType` instead
Expand Down Expand Up @@ -949,6 +950,13 @@ function makeStore(storeClass: Class<Store>): Store {

[⇧ back to top](#flows-utility-types)

### mixed

An arbitrary type that could be anything (same as `unknown`)
https://flow.org/en/docs/types/mixed

[⇧ back to top](#table-of-contents)

---

MIT License
Expand Down
2 changes: 2 additions & 0 deletions src/__snapshots__/utility-types.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ exports[`$Shape testType<$Shape<Props>>() 1`] = `"Partial<Props>"`;
exports[`$Values testType<$Values<Props>>() 1`] = `"string | number | boolean"`;
exports[`Class testType<Class<Foo>>() 1`] = `"Class<Foo>"`;
exports[`mixed testType<mixed>() 1`] = `"unknown"`;
7 changes: 7 additions & 0 deletions src/utility-types.spec.snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
$Shape,
$NonMaybeType,
Class,
mixed,
} from './utility-types';
import { _DeepReadonlyObject } from './mapped-types';
/**
Expand Down Expand Up @@ -113,3 +114,9 @@ it('Class', () => {
// @dts-jest:pass:snap -> Class<Foo>
testType<Class<Foo>>();
});

// @dts-jest:group mixed
it('mixed', () => {
// @dts-jest:pass:snap -> unknown
testType<mixed>();
});
7 changes: 7 additions & 0 deletions src/utility-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
$Shape,
$NonMaybeType,
Class,
mixed,
} from './utility-types';
import { _DeepReadonlyObject } from './mapped-types';
/**
Expand Down Expand Up @@ -113,3 +114,9 @@ it('Class', () => {
// @dts-jest:pass:snap
testType<Class<Foo>>();
});

// @dts-jest:group mixed
it('mixed', () => {
// @dts-jest:pass:snap
testType<mixed>();
});
17 changes: 17 additions & 0 deletions src/utility-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,20 @@ export type $NonMaybeType<T> = NonNullable<T>;
* }
*/
export type Class<T> = new (...args: any[]) => T;

/**
* mixed
* @desc An arbitrary type that could be anything
* @see https://flow.org/en/docs/types/mixed
* @example
*
* function stringify(value: mixed) {
* // ...
* }
*
* stringify("foo");
* stringify(3.14);
* stringify(null);
* stringify({});
*/
export type mixed = unknown;

0 comments on commit 8de38fe

Please sign in to comment.