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

Add mixed type #81

Merged
merged 9 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from 7 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Issues can be funded by anyone and the money will be transparently distributed t

* [`Primitive`](#primitive)
* [`Falsey`](#falsey)
* [`mixed`](#mixed)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move it as the first item in "Flow's Utility Types" section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it count as utility type tho?

Copy link
Owner

@piotrwitek piotrwitek Apr 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only for Flow's migration, nobody using primarily TS would ever want to use it


## Union operators

Expand Down Expand Up @@ -138,6 +139,13 @@ Type representing falsey values in TypeScript: `null | undefined | false | 0 | '

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

### mixed

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

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 145, please add a link to the flow docs so it looks consistent with all the remaining flow types

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still has wrong formatting, not showing below the description, please check how it's done in other types

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hint: two spaces at the end of prev line

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

### `SetIntersection<A, B>` (same as Extract)

Set intersection of given union types `A` and `B`
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;