-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe88deb
commit 1bbfa6a
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { expectError, expectType } from 'tsd'; | ||
|
||
import { __, maxBy, prop } from '../es'; | ||
|
||
type Obj = { | ||
str: string; | ||
date: Date; | ||
bool: boolean; | ||
}; | ||
|
||
// please note how literals work in this situation | ||
expectType<1 | 2>(maxBy(Math.abs, 1, 2)); | ||
// using variables that are type `number` is the more general use-case here | ||
const a: number = 1; | ||
const b: number = 2; | ||
expectType<number>(maxBy(Math.abs, a, b)); | ||
// so can also upcast inline to get the same result | ||
expectType<number>(maxBy(Math.abs, 1 as number, 2 as number)); | ||
// now check the other Ord types | ||
expectType<Obj>(maxBy(prop('str'), {} as Obj, {} as Obj)); | ||
expectType<Obj>(maxBy(prop('bool'), {} as Obj, {} as Obj)); | ||
expectType<Obj>(maxBy(prop('date'), {} as Obj, {} as Obj)); | ||
|
||
// Placeholder | ||
// expectType<number>(max(__, b)(a)); | ||
expectType<number>(maxBy(__, 1 as number, 2 as number)(Math.abs)); | ||
// curried | ||
// notice how literals work fine here because `T` is pulled directly from Math.abs | ||
// in the full function typescript will hard union them, but here it cannot | ||
expectType<number>(maxBy(Math.abs)(1)(2)); | ||
|
||
// don't allow different types | ||
expectError(maxBy(Math.abs, 1, '2')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { expectError, expectType } from 'tsd'; | ||
|
||
import { __, minBy, prop } from '../es'; | ||
|
||
type Obj = { | ||
str: string; | ||
date: Date; | ||
bool: boolean; | ||
}; | ||
|
||
// please note how literals work in this situation | ||
expectType<1 | 2>(minBy(Math.abs, 1, 2)); | ||
// using variables that are type `number` is the more general use-case here | ||
const a: number = 1; | ||
const b: number = 2; | ||
expectType<number>(minBy(Math.abs, a, b)); | ||
// so can also upcast inline to get the same result | ||
expectType<number>(minBy(Math.abs, 1 as number, 2 as number)); | ||
// now check the other Ord types | ||
expectType<Obj>(minBy(prop('str'), {} as Obj, {} as Obj)); | ||
expectType<Obj>(minBy(prop('bool'), {} as Obj, {} as Obj)); | ||
expectType<Obj>(minBy(prop('date'), {} as Obj, {} as Obj)); | ||
|
||
// Placeholder | ||
// expectType<number>(max(__, b)(a)); | ||
expectType<number>(minBy(__, 1 as number, 2 as number)(Math.abs)); | ||
// curried | ||
// notice how literals work fine here because `T` is pulled directly from Math.abs | ||
// in the full function typescript will hard union them, but here it cannot | ||
expectType<number>(minBy(Math.abs)(1)(2)); | ||
|
||
// don't allow different types | ||
expectError(minBy(Math.abs, 1, '2')); |