diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7d43e5d..a4374b1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,6 +20,16 @@ Feature suggestions are welcome, but please be aware that: Below are the guidelines for submitting a pull request. +### Preparations + +If you are working on Windows, you may need to enable support for long paths in Git, othwise cloning the submodule may fail. Open an administrator shell, and execute `git config --system core.longpaths true`. + +In the cloned repository: + +1. `git submodule init` +2. `git submodule update` (downloading the 3 GB sized TypeScript repository will take a while ...) +3. `npm install` + ### How to change type definitions better-typescript-lib replaces the built-in type definitions with its own ones. The renewed definitions are in the `lib/` directory. @@ -49,7 +59,7 @@ For other declarations, such as type aliases, enums, and namespaces, the replace ### Committing Build Artifacts -Currently, build artifacts needs to be committed. Follow the following steps to build and commit them. +Currently, build artifacts need to be committed. Follow the steps below to build and commit them. 1. `npm run build:tsc` 2. `npm run build:lib` diff --git a/docs/diff/es5.d.ts.md b/docs/diff/es5.d.ts.md index 6ae6c9e..c53c76c 100644 --- a/docs/diff/es5.d.ts.md +++ b/docs/diff/es5.d.ts.md @@ -793,10 +793,10 @@ Index: es5.d.ts - | undefined - | null, - ): PromiseLike; -+ then( -+ onfulfilled?: null | undefined, -+ onrejected?: ((reason: unknown) => T | PromiseLike) | null | undefined, -+ ): PromiseLike; ++ then( ++ onfulfilled: (value: T) => U | PromiseLike, ++ onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, ++ ): PromiseLike; + + /** + * Attaches callbacks for the resolution and/or rejection of the Promise. @@ -805,9 +805,9 @@ Index: es5.d.ts + * @returns A Promise for the completion of which ever callback is executed. + */ + then( -+ onfulfilled: (value: T) => U | PromiseLike, ++ onfulfilled: ((value: T) => U | PromiseLike) | null | undefined, + onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, -+ ): PromiseLike; ++ ): PromiseLike; } -/** @@ -831,10 +831,10 @@ Index: es5.d.ts - | undefined - | null, - ): Promise; -+ then( -+ onfulfilled?: null | undefined, -+ onrejected?: ((reason: unknown) => T | PromiseLike) | null | undefined, -+ ): Promise; ++ then( ++ onfulfilled: (value: T) => U | PromiseLike, ++ onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, ++ ): Promise; /** + * Attaches callbacks for the resolution and/or rejection of the Promise. @@ -843,9 +843,9 @@ Index: es5.d.ts + * @returns A Promise for the completion of which ever callback is executed. + */ + then( -+ onfulfilled: (value: T) => U | PromiseLike, ++ onfulfilled: ((value: T) => U | PromiseLike) | null | undefined, + onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, -+ ): Promise; ++ ): Promise; + + /** * Attaches a callback for only the rejection of the Promise. @@ -858,9 +858,9 @@ Index: es5.d.ts - | undefined - | null, - ): Promise; -+ catch( -+ onrejected?: ((reason: unknown) => T | PromiseLike) | null | undefined, -+ ): Promise; ++ catch( ++ onrejected: ((reason: unknown) => U | PromiseLike) | null | undefined, ++ ): Promise; } /** diff --git a/generated/lib.es5.d.ts b/generated/lib.es5.d.ts index 7dc5a5b..dcbc6cc 100644 --- a/generated/lib.es5.d.ts +++ b/generated/lib.es5.d.ts @@ -2095,10 +2095,10 @@ interface PromiseLike { * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the completion of which ever callback is executed. */ - then( - onfulfilled?: null | undefined, - onrejected?: ((reason: unknown) => T | PromiseLike) | null | undefined, - ): PromiseLike; + then( + onfulfilled: (value: T) => U | PromiseLike, + onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, + ): PromiseLike; /** * Attaches callbacks for the resolution and/or rejection of the Promise. @@ -2107,9 +2107,9 @@ interface PromiseLike { * @returns A Promise for the completion of which ever callback is executed. */ then( - onfulfilled: (value: T) => U | PromiseLike, + onfulfilled: ((value: T) => U | PromiseLike) | null | undefined, onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, - ): PromiseLike; + ): PromiseLike; } // /** // * Attaches callbacks for the resolution and/or rejection of the Promise. @@ -2126,10 +2126,10 @@ interface Promise extends PromiseLike { * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the completion of which ever callback is executed. */ - then( - onfulfilled?: null | undefined, - onrejected?: ((reason: unknown) => T | PromiseLike) | null | undefined, - ): Promise; + then( + onfulfilled: (value: T) => U | PromiseLike, + onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, + ): Promise; /** * Attaches callbacks for the resolution and/or rejection of the Promise. @@ -2138,18 +2138,18 @@ interface Promise extends PromiseLike { * @returns A Promise for the completion of which ever callback is executed. */ then( - onfulfilled: (value: T) => U | PromiseLike, + onfulfilled: ((value: T) => U | PromiseLike) | null | undefined, onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, - ): Promise; + ): Promise; /** * Attaches a callback for only the rejection of the Promise. * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the completion of the callback. */ - catch( - onrejected?: ((reason: unknown) => T | PromiseLike) | null | undefined, - ): Promise; + catch( + onrejected: ((reason: unknown) => U | PromiseLike) | null | undefined, + ): Promise; } // /** // * Represents the completion of an asynchronous operation diff --git a/lib/lib.es5.d.ts b/lib/lib.es5.d.ts index b808a5e..329c95a 100644 --- a/lib/lib.es5.d.ts +++ b/lib/lib.es5.d.ts @@ -587,10 +587,10 @@ interface PromiseLike { * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the completion of which ever callback is executed. */ - then( - onfulfilled?: null | undefined, - onrejected?: ((reason: unknown) => T | PromiseLike) | null | undefined, - ): PromiseLike; + then( + onfulfilled: (value: T) => U | PromiseLike, + onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, + ): PromiseLike; /** * Attaches callbacks for the resolution and/or rejection of the Promise. @@ -599,9 +599,9 @@ interface PromiseLike { * @returns A Promise for the completion of which ever callback is executed. */ then( - onfulfilled: (value: T) => U | PromiseLike, + onfulfilled: ((value: T) => U | PromiseLike) | null | undefined, onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, - ): PromiseLike; + ): PromiseLike; } interface Promise extends PromiseLike { @@ -611,10 +611,10 @@ interface Promise extends PromiseLike { * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the completion of which ever callback is executed. */ - then( - onfulfilled?: null | undefined, - onrejected?: ((reason: unknown) => T | PromiseLike) | null | undefined, - ): Promise; + then( + onfulfilled: (value: T) => U | PromiseLike, + onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, + ): Promise; /** * Attaches callbacks for the resolution and/or rejection of the Promise. @@ -623,18 +623,18 @@ interface Promise extends PromiseLike { * @returns A Promise for the completion of which ever callback is executed. */ then( - onfulfilled: (value: T) => U | PromiseLike, + onfulfilled: ((value: T) => U | PromiseLike) | null | undefined, onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, - ): Promise; + ): Promise; /** * Attaches a callback for only the rejection of the Promise. * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the completion of the callback. */ - catch( - onrejected?: ((reason: unknown) => T | PromiseLike) | null | undefined, - ): Promise; + catch( + onrejected: ((reason: unknown) => U | PromiseLike) | null | undefined, + ): Promise; } interface TypedNumberArray< diff --git a/tests/src/es5.ts b/tests/src/es5.ts index cf34e39..37a8e66 100644 --- a/tests/src/es5.ts +++ b/tests/src/es5.ts @@ -39,8 +39,6 @@ const testPromiseConstructorLike = (MyPromise: PromiseConstructorLike) => { }; // Promise const testPromise = (promise: Promise) => { - expectType>(promise.then()); - expectType>(promise.catch()); expectType>(promise.then(null)); expectType>(promise.then(undefined)); expectType>(promise.catch(null)); @@ -70,6 +68,14 @@ const testPromise = (promise: Promise) => { (err) => Promise.resolve(`${err}`.length), ), ); + expectType>(promise.then(() => 42, () => 42)); + expectType>(promise.then(null, () => 42)); + expectType>(promise.then(undefined, () => 42)); + expectType>(promise.catch(() => 42)); + // @ts-expect-error + promise.then(); + // @ts-expect-error + promise.catch(); // @ts-expect-error promise.then((str: string) => str); promise.then( @@ -78,8 +84,6 @@ const testPromise = (promise: Promise) => { () => "NaN", ); // @ts-expect-error - promise.then(null, (err) => `${err}`.length); - // @ts-expect-error promise.catch(null, (err) => `${err}`.length); }; @@ -525,4 +529,4 @@ expectType<{ foo: number; bar: string; baz: boolean }>( } } -export {}; +export { };