-
Notifications
You must be signed in to change notification settings - Fork 23
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
1972559
commit ddbfb05
Showing
2 changed files
with
33 additions
and
1 deletion.
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,32 @@ | ||
import { expectError, expectType } from 'tsd'; | ||
|
||
import { flow } from '../es'; | ||
|
||
const strToNum = (str: string) => Number(str); | ||
const numToStr = (num: number) => String(num); | ||
|
||
expectType<number>(flow(1, [])); | ||
expectType<string>(flow(1, [numToStr])); | ||
expectType<number>(flow(1, [numToStr, strToNum])); | ||
expectType<string>(flow(1, [numToStr, strToNum, numToStr])); | ||
expectType<number>(flow(1, [numToStr, strToNum, numToStr, strToNum])); | ||
expectType<string>(flow(1, [numToStr, strToNum, numToStr, strToNum, numToStr])); | ||
expectType<number>(flow(1, [numToStr, strToNum, numToStr, strToNum, numToStr, strToNum])); | ||
expectType<string>(flow(1, [numToStr, strToNum, numToStr, strToNum, numToStr, strToNum, numToStr])); | ||
expectType<number>(flow(1, [numToStr, strToNum, numToStr, strToNum, numToStr, strToNum, numToStr, strToNum])); | ||
expectType<string>(flow(1, [numToStr, strToNum, numToStr, strToNum, numToStr, strToNum, numToStr, strToNum, numToStr])); | ||
|
||
// with 10+, if you don't set the generic it returns unknown | ||
expectType<unknown>(flow(1, [numToStr, strToNum, numToStr, strToNum, numToStr, strToNum, numToStr, strToNum, numToStr, strToNum])); | ||
// setting the final return type has no typechecking against the actual chain of functions | ||
expectType<Date>(flow<number, Date>(1, [numToStr, strToNum, numToStr, strToNum, numToStr, strToNum, numToStr, strToNum, numToStr, strToNum])); | ||
// the Seed type has to match though, or it will error | ||
expectError(flow<string, Date>(1, [numToStr, strToNum, numToStr, strToNum, numToStr, strToNum, numToStr, strToNum, numToStr, strToNum])); | ||
|
||
// same applies if you have generic array of functions, even if the arg and return are typed | ||
const seriesOfFunctions: Array<(a: string) => string> = []; | ||
expectType<unknown>(flow(1, seriesOfFunctions)); | ||
// setting the final return type has no typechecking against the actual chain of functions | ||
expectType<Date>(flow<number, Date>(1, seriesOfFunctions)); | ||
// the Seed type has to match though, or it will error | ||
expectError(flow<string, Date>(1, seriesOfFunctions)); |
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