forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(45901): Error 1064 should apply to @callback definitions in the s…
…ame way as @param, but doesn't (microsoft#54625)
- Loading branch information
1 parent
b1bec34
commit 9b4aa36
Showing
7 changed files
with
342 additions
and
15 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
73 changes: 73 additions & 0 deletions
73
tests/baselines/reference/asyncFunctionDeclaration16_es5.errors.txt
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,73 @@ | ||
/a.js(21,14): error TS1055: Type 'string' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. | ||
/a.js(27,12): error TS1065: The return type of an async function or method must be the global Promise<T> type. | ||
/a.js(45,12): error TS1065: The return type of an async function or method must be the global Promise<T> type. | ||
Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. | ||
Construct signature return types 'Thenable' and 'PromiseLike<T>' are incompatible. | ||
The types returned by 'then(...)' are incompatible between these types. | ||
Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'. | ||
|
||
|
||
==== /types.d.ts (0 errors) ==== | ||
declare class Thenable { then(): void; } | ||
|
||
==== /a.js (3 errors) ==== | ||
/** | ||
* @callback T1 | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
|
||
/** | ||
* @callback T2 | ||
* @param {string} str | ||
* @returns {Promise<string>} | ||
*/ | ||
|
||
/** | ||
* @callback T3 | ||
* @param {string} str | ||
* @returns {Thenable} | ||
*/ | ||
|
||
/** | ||
* @param {string} str | ||
* @returns {string} | ||
~~~~~~ | ||
!!! error TS1055: Type 'string' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. | ||
*/ | ||
const f1 = async str => { | ||
return str; | ||
} | ||
|
||
/** @type {T1} */ | ||
~~ | ||
!!! error TS1065: The return type of an async function or method must be the global Promise<T> type. | ||
!!! related TS1055 /a.js:4:14: Type 'string' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. | ||
const f2 = async str => { | ||
return str; | ||
} | ||
|
||
/** | ||
* @param {string} str | ||
* @returns {Promise<string>} | ||
*/ | ||
const f3 = async str => { | ||
return str; | ||
} | ||
|
||
/** @type {T2} */ | ||
const f4 = async str => { | ||
return str; | ||
} | ||
|
||
/** @type {T3} */ | ||
~~ | ||
!!! error TS1065: The return type of an async function or method must be the global Promise<T> type. | ||
!!! error TS1065: Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. | ||
!!! error TS1065: Construct signature return types 'Thenable' and 'PromiseLike<T>' are incompatible. | ||
!!! error TS1065: The types returned by 'then(...)' are incompatible between these types. | ||
!!! error TS1065: Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'. | ||
const f5 = async str => { | ||
return str; | ||
} | ||
|
77 changes: 77 additions & 0 deletions
77
tests/baselines/reference/asyncFunctionDeclaration16_es5.symbols
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,77 @@ | ||
//// [tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration16_es5.ts] //// | ||
|
||
=== /types.d.ts === | ||
declare class Thenable { then(): void; } | ||
>Thenable : Symbol(Thenable, Decl(types.d.ts, 0, 0)) | ||
>then : Symbol(Thenable.then, Decl(types.d.ts, 0, 24)) | ||
|
||
=== /a.js === | ||
/** | ||
* @callback T1 | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
|
||
/** | ||
* @callback T2 | ||
* @param {string} str | ||
* @returns {Promise<string>} | ||
*/ | ||
|
||
/** | ||
* @callback T3 | ||
* @param {string} str | ||
* @returns {Thenable} | ||
*/ | ||
|
||
/** | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
const f1 = async str => { | ||
>f1 : Symbol(f1, Decl(a.js, 22, 5)) | ||
>str : Symbol(str, Decl(a.js, 22, 16)) | ||
|
||
return str; | ||
>str : Symbol(str, Decl(a.js, 22, 16)) | ||
} | ||
|
||
/** @type {T1} */ | ||
const f2 = async str => { | ||
>f2 : Symbol(f2, Decl(a.js, 27, 5)) | ||
>str : Symbol(str, Decl(a.js, 27, 16)) | ||
|
||
return str; | ||
>str : Symbol(str, Decl(a.js, 27, 16)) | ||
} | ||
|
||
/** | ||
* @param {string} str | ||
* @returns {Promise<string>} | ||
*/ | ||
const f3 = async str => { | ||
>f3 : Symbol(f3, Decl(a.js, 35, 5)) | ||
>str : Symbol(str, Decl(a.js, 35, 16)) | ||
|
||
return str; | ||
>str : Symbol(str, Decl(a.js, 35, 16)) | ||
} | ||
|
||
/** @type {T2} */ | ||
const f4 = async str => { | ||
>f4 : Symbol(f4, Decl(a.js, 40, 5)) | ||
>str : Symbol(str, Decl(a.js, 40, 16)) | ||
|
||
return str; | ||
>str : Symbol(str, Decl(a.js, 40, 16)) | ||
} | ||
|
||
/** @type {T3} */ | ||
const f5 = async str => { | ||
>f5 : Symbol(f5, Decl(a.js, 45, 5)) | ||
>str : Symbol(str, Decl(a.js, 45, 16)) | ||
|
||
return str; | ||
>str : Symbol(str, Decl(a.js, 45, 16)) | ||
} | ||
|
82 changes: 82 additions & 0 deletions
82
tests/baselines/reference/asyncFunctionDeclaration16_es5.types
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,82 @@ | ||
//// [tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration16_es5.ts] //// | ||
|
||
=== /types.d.ts === | ||
declare class Thenable { then(): void; } | ||
>Thenable : Thenable | ||
>then : () => void | ||
|
||
=== /a.js === | ||
/** | ||
* @callback T1 | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
|
||
/** | ||
* @callback T2 | ||
* @param {string} str | ||
* @returns {Promise<string>} | ||
*/ | ||
|
||
/** | ||
* @callback T3 | ||
* @param {string} str | ||
* @returns {Thenable} | ||
*/ | ||
|
||
/** | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
const f1 = async str => { | ||
>f1 : (str: string) => string | ||
>async str => { return str;} : (str: string) => string | ||
>str : string | ||
|
||
return str; | ||
>str : string | ||
} | ||
|
||
/** @type {T1} */ | ||
const f2 = async str => { | ||
>f2 : T1 | ||
>async str => { return str;} : (str: string) => string | ||
>str : string | ||
|
||
return str; | ||
>str : string | ||
} | ||
|
||
/** | ||
* @param {string} str | ||
* @returns {Promise<string>} | ||
*/ | ||
const f3 = async str => { | ||
>f3 : (str: string) => Promise<string> | ||
>async str => { return str;} : (str: string) => Promise<string> | ||
>str : string | ||
|
||
return str; | ||
>str : string | ||
} | ||
|
||
/** @type {T2} */ | ||
const f4 = async str => { | ||
>f4 : T2 | ||
>async str => { return str;} : (str: string) => Promise<string> | ||
>str : string | ||
|
||
return str; | ||
>str : string | ||
} | ||
|
||
/** @type {T3} */ | ||
const f5 = async str => { | ||
>f5 : T3 | ||
>async str => { return str;} : (str: string) => Thenable | ||
>str : string | ||
|
||
return str; | ||
>str : string | ||
} | ||
|
Oops, something went wrong.