-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix funtion-partial export type (#507)
- Loading branch information
Showing
2 changed files
with
66 additions
and
62 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
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 |
---|---|---|
@@ -1,106 +1,106 @@ | ||
import { partial } from './index'; | ||
import partial from './index'; | ||
|
||
// Case 1) one aurgument. | ||
const sqrt = partial(Math.sqrt) | ||
sqrt(16) | ||
const sqrt = partial(Math.sqrt); | ||
sqrt(16); | ||
|
||
// @ts-expect-error | ||
sqrt() | ||
sqrt(); | ||
// @ts-expect-error | ||
sqrt(2, 2) | ||
sqrt(2, 2); | ||
// @ts-expect-error | ||
sqrt(true) | ||
sqrt(true); | ||
|
||
const sqrtOf16 = partial(Math.sqrt, 16) | ||
sqrtOf16() | ||
const sqrtOf16 = partial(Math.sqrt, 16); | ||
sqrtOf16(); | ||
|
||
// @ts-expect-error | ||
sqrtOf16(16) | ||
sqrtOf16(16); | ||
|
||
// Case 2) Two arguments. | ||
const repeat = (str: string, n: number) => { | ||
return str.repeat(n) | ||
} | ||
return str.repeat(n); | ||
}; | ||
|
||
const anotherRepeat = partial(repeat) | ||
anotherRepeat("a", 2) | ||
const anotherRepeat = partial(repeat); | ||
anotherRepeat('a', 2); | ||
|
||
// @ts-expect-error | ||
anotherRepeat() | ||
anotherRepeat(); | ||
// @ts-expect-error | ||
anotherRepeat("a") | ||
anotherRepeat('a'); | ||
// @ts-expect-error | ||
anotherRepeat(2) | ||
anotherRepeat(2); | ||
// @ts-expect-error | ||
anotherRepeat(2, "a") | ||
anotherRepeat(2, 'a'); | ||
|
||
const repeatHello = partial(repeat, "hello, ") | ||
repeatHello(10) | ||
const repeatHello = partial(repeat, 'hello, '); | ||
repeatHello(10); | ||
|
||
// @ts-expect-error | ||
repeatHello() | ||
repeatHello(); | ||
// @ts-expect-error | ||
repeatHello([]) | ||
repeatHello([]); | ||
|
||
const repeat3Times = partial(repeat, undefined, 3) | ||
repeat3Times('hello, ') | ||
const repeat3Times = partial(repeat, undefined, 3); | ||
repeat3Times('hello, '); | ||
|
||
// @ts-expect-error | ||
repeat3Times() | ||
repeat3Times(); | ||
// @ts-expect-error | ||
repeat3Times({}) | ||
repeat3Times({}); | ||
|
||
const repeatHello3Times = partial(repeat, "hello, ", 3) | ||
repeatHello3Times() | ||
const repeatHello3Times = partial(repeat, 'hello, ', 3); | ||
repeatHello3Times(); | ||
|
||
// @ts-expect-error | ||
repeatHello3Times(1, 2, 3) | ||
repeatHello3Times(1, 2, 3); | ||
|
||
// Case 3) three arguments. | ||
const getFormattedPrice = (amount: number, unit: string, includeTax: boolean) => { | ||
const tax = includeTax ? 1.1 : 1 | ||
return `${unit}${amount * tax}` | ||
} | ||
const tax = includeTax ? 1.1 : 1; | ||
return `${unit}${amount * tax}`; | ||
}; | ||
|
||
const anotherGetFormattedPrice = partial(getFormattedPrice) | ||
anotherGetFormattedPrice(100, "$", true) | ||
const anotherGetFormattedPrice = partial(getFormattedPrice); | ||
anotherGetFormattedPrice(100, '$', true); | ||
|
||
// @ts-expect-error | ||
anotherGetFormattedPrice({}) | ||
anotherGetFormattedPrice({}); | ||
|
||
const getFormattedPriceWithTax = partial(getFormattedPrice, undefined, undefined, true) | ||
getFormattedPriceWithTax(100, "€") | ||
const getFormattedPriceWithTax = partial(getFormattedPrice, undefined, undefined, true); | ||
getFormattedPriceWithTax(100, '€'); | ||
|
||
const getFormattedPriceInUS = partial(getFormattedPrice, undefined, "$", undefined) | ||
getFormattedPriceInUS(100, false) | ||
const getFormattedPriceInUS = partial(getFormattedPrice, undefined, '$', undefined); | ||
getFormattedPriceInUS(100, false); | ||
|
||
const getFormattedCookiePrice = partial(getFormattedPrice, 100, undefined, undefined) | ||
getFormattedCookiePrice("$", false) | ||
const getFormattedCookiePrice = partial(getFormattedPrice, 100, undefined, undefined); | ||
getFormattedCookiePrice('$', false); | ||
|
||
const getFormattedCookiePriceInUS = partial(getFormattedPrice, 100, "$", undefined) | ||
getFormattedCookiePriceInUS(true) | ||
const getFormattedCookiePriceInUS = partial(getFormattedPrice, 100, '$', undefined); | ||
getFormattedCookiePriceInUS(true); | ||
|
||
const getFormattedCookiePriceWithoutTax = partial(getFormattedPrice, 100, undefined, false) | ||
getFormattedCookiePriceWithoutTax("¥") | ||
const getFormattedCookiePriceWithoutTax = partial(getFormattedPrice, 100, undefined, false); | ||
getFormattedCookiePriceWithoutTax('¥'); | ||
|
||
const getFormattedPriceWithTaxInUS = partial(getFormattedPrice, undefined, "$", true) | ||
getFormattedPriceWithTaxInUS(10000) | ||
const getFormattedPriceWithTaxInUS = partial(getFormattedPrice, undefined, '$', true); | ||
getFormattedPriceWithTaxInUS(10000); | ||
|
||
const getFormattedCookiePriceWithTaxInUS = partial(getFormattedPrice, 100, "$", true) | ||
getFormattedCookiePriceWithTaxInUS() | ||
const getFormattedCookiePriceWithTaxInUS = partial(getFormattedPrice, 100, '$', true); | ||
getFormattedCookiePriceWithTaxInUS(); | ||
|
||
// Case 4) arbitrarily many arguments. | ||
const consoleLog = partial(console.log) | ||
consoleLog("hello", ", ", "world") | ||
const consoleLog = partial(console.log); | ||
consoleLog('hello', ', ', 'world'); | ||
|
||
const logHello = partial(console.log, "Hello") | ||
logHello() | ||
const logHello = partial(console.log, 'Hello'); | ||
logHello(); | ||
|
||
const logHelloWorld = partial(console.log, "Hello", ", ", "world") | ||
logHelloWorld() | ||
const logHelloWorld = partial(console.log, 'Hello', ', ', 'world'); | ||
logHelloWorld(); | ||
|
||
const logGreetWorld = partial(console.log, undefined, ", ", "world") | ||
logGreetWorld("Good Afternoon") | ||
const logGreetWorld = partial(console.log, undefined, ', ', 'world'); | ||
logGreetWorld('Good Afternoon'); | ||
|
||
const logGreetToSomeone = partial(console.log, undefined, ", ") | ||
logGreetToSomeone("Good Afternoon", "World", "!") | ||
const logGreetToSomeone = partial(console.log, undefined, ', '); | ||
logGreetToSomeone('Good Afternoon', 'World', '!'); |