diff --git a/docs/1058.md b/docs/1058.md index 1b513fb..801fd6e 100644 --- a/docs/1058.md +++ b/docs/1058.md @@ -1,4 +1,31 @@ --- title: "The return type of an async function must either be a valid promise or must not contain a callable 'then' member." category: error +tags: +- async +- syntax-error +- promises +related: +- 1059 +- 1060 --- + +Async functions cannot return objects with a callable then property as +Javascript aggressively flattens promises. Therefore the following is an error: + +```ts +class A { + async test() { + return { + then() {}, + }; + } +} +``` + +### See also + +- [StackOverflow - Typescript error when function return type is Promise<{ then: () => void }>](https://stackoverflow.com/questions/47111363/typescript-error-when-function-return-type-is-promise-then-void) +- [StackOverflow - Fulfill (don't resolve) promise with another promise](https://stackoverflow.com/questions/32168194/fulfill-dont-resolve-promise-with-another-promise) +- [Monads for the Rest of Us - Why Promises are not Monads](https://gist.github.com/fatcerberus/beae4d15842071eab24fca2f0740c2ef#monads-its-the-law) +- [MDN - `Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) diff --git a/docs/1058_fix_01.md b/docs/1058_fix_01.md new file mode 100644 index 0000000..3b981ba --- /dev/null +++ b/docs/1058_fix_01.md @@ -0,0 +1,16 @@ +--- +title: "Rename the method/property." +--- + +The best fix for this error is to rename the `then` method on the object you are +returning to something else. `chain` or `map` might be appropriate: + +```ts +class A { + async test() { + return { + chain() {}, + }; + } +} +``` diff --git a/docs/1059.md b/docs/1059.md index f6e561c..96aa58f 100644 --- a/docs/1059.md +++ b/docs/1059.md @@ -1,4 +1,14 @@ --- title: "A promise must have a 'then' method." category: error +tags: +- promise +- typescript-only +- async +related: +- 1058 +- 1060 --- + +This is caused by the global `Promise` not containing a callable `then` method +and therefore not supporting `async`/`await` downlevel emit. diff --git a/docs/1059_fix_01.md b/docs/1059_fix_01.md new file mode 100644 index 0000000..5e9124e --- /dev/null +++ b/docs/1059_fix_01.md @@ -0,0 +1,7 @@ +--- +title: "Issue with types." +--- + +The most common fix for this is that is the types for the 3rd party promise +library is not configured properly. Refer to current documentation for using the +3rd party promise library. diff --git a/docs/1060.md b/docs/1060.md index 65edc87..7408677 100644 --- a/docs/1060.md +++ b/docs/1060.md @@ -1,4 +1,11 @@ --- title: "The first parameter of the 'then' method of a promise must be a callback." category: error +tags: +- promise +- typescript-only +- async --- + +This is caused by the global `Promise` not having a compatible signature to +support `async`/`await` downlevel emit. diff --git a/docs/1060_fix_01.md b/docs/1060_fix_01.md new file mode 100644 index 0000000..4f437a0 --- /dev/null +++ b/docs/1060_fix_01.md @@ -0,0 +1,8 @@ +--- +title: "Issue with promise library." +--- + +Either the 3rd party promise library cannot be used with TypeScript to down +level emit `async`/`await` or there is a configuration issue with the library +that is not allowing TypeScript to understand it will work. Consult the current +documentation for the 3rd party promise library. diff --git a/docs/1061.md b/docs/1061.md index 93c96dd..7f0f773 100644 --- a/docs/1061.md +++ b/docs/1061.md @@ -1,4 +1,17 @@ --- title: "Enum member must have initializer." category: error +tags: +- enums +- typescript-only --- + +When an enum contains string members, TypeScript cannot infer the value of +members. Therefore the following will error: + +```ts +enum A { + a = "1", + b, +} +``` diff --git a/docs/1061_fix_01.md b/docs/1061_fix_01.md new file mode 100644 index 0000000..37d8616 --- /dev/null +++ b/docs/1061_fix_01.md @@ -0,0 +1,12 @@ +--- +title: "Provide an initializer for each member." +--- + +Explicitly initialize the member: + +```ts +enum A { + a = "1", + b = "2", +} +``` diff --git a/docs/1062.md b/docs/1062.md index dbf3c2a..2870e75 100644 --- a/docs/1062.md +++ b/docs/1062.md @@ -1,4 +1,23 @@ --- title: "Type is referenced directly or indirectly in the fulfillment callback of its own 'then' method." category: error +tags: +- promise +- async --- + +When implementing a non-native promise type, if the type references itself in +the `then`` method, this error will occur: + +```ts +declare class BadPromise { + then( + onfulfilled: (value: BadPromise) => any, + onrejected: (error: any) => any, + ): BadPromise; +} + +async function test() { + await new BadPromise(); +} +``` diff --git a/docs/1062_fix_01.md b/docs/1062_fix_01.md new file mode 100644 index 0000000..99a9d61 --- /dev/null +++ b/docs/1062_fix_01.md @@ -0,0 +1,5 @@ +--- +title: "Don't use a recursive type." +--- + +To fix the error, don't use a recursive type in the definition of the promise.