Skip to content

Commit 21b5c96

Browse files
authored
Add an extra test case for an error on async function typed using @type (#58217)
1 parent b1d821a commit 21b5c96

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

Diff for: tests/baselines/reference/asyncArrowFunction_allowJs.errors.txt

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ file.js(6,24): error TS1064: The return type of an async function or method must
33
file.js(7,23): error TS2322: Type 'number' is not assignable to type 'string'.
44
file.js(10,24): error TS1064: The return type of an async function or method must be the global Promise<T> type. Did you mean to write 'Promise<string>'?
55
file.js(12,2): error TS2322: Type 'number' is not assignable to type 'string'.
6-
file.js(19,3): error TS2345: Argument of type '() => Promise<number>' is not assignable to parameter of type '() => string'.
6+
file.js(16,24): error TS1064: The return type of an async function or method must be the global Promise<T> type. Did you mean to write 'Promise<string>'?
7+
file.js(25,3): error TS2345: Argument of type '() => Promise<number>' is not assignable to parameter of type '() => string'.
78
Type 'Promise<number>' is not assignable to type 'string'.
89

910

10-
==== file.js (6 errors) ====
11+
==== file.js (7 errors) ====
1112
// Error (good)
1213
/** @type {function(): string} */
1314
const a = () => 0
@@ -32,6 +33,14 @@ file.js(19,3): error TS2345: Argument of type '() => Promise<number>' is not ass
3233
!!! error TS2322: Type 'number' is not assignable to type 'string'.
3334
}
3435

36+
// Error (good)
37+
/** @type {function(): string} */
38+
~~~~~~
39+
!!! error TS1064: The return type of an async function or method must be the global Promise<T> type. Did you mean to write 'Promise<string>'?
40+
const d = async () => {
41+
return ""
42+
}
43+
3544
/** @type {function(function(): string): void} */
3645
const f = (p) => {}
3746

Diff for: tests/baselines/reference/asyncArrowFunction_allowJs.symbols

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,22 @@ const c = async () => {
1919
return 0
2020
}
2121

22+
// Error (good)
23+
/** @type {function(): string} */
24+
const d = async () => {
25+
>d : Symbol(d, Decl(file.js, 16, 5))
26+
27+
return ""
28+
}
29+
2230
/** @type {function(function(): string): void} */
2331
const f = (p) => {}
24-
>f : Symbol(f, Decl(file.js, 15, 5))
25-
>p : Symbol(p, Decl(file.js, 15, 11))
32+
>f : Symbol(f, Decl(file.js, 21, 5))
33+
>p : Symbol(p, Decl(file.js, 21, 11))
2634

2735
// Error (good)
2836
f(async () => {
29-
>f : Symbol(f, Decl(file.js, 15, 5))
37+
>f : Symbol(f, Decl(file.js, 21, 5))
3038

3139
return 0
3240
})

Diff for: tests/baselines/reference/asyncArrowFunction_allowJs.types

+13
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ const c = async () => {
3434
> : ^
3535
}
3636

37+
// Error (good)
38+
/** @type {function(): string} */
39+
const d = async () => {
40+
>d : () => string
41+
> : ^^^^^^^^^^^^
42+
>async () => { return ""} : () => string
43+
> : ^^^^^^^^^^^^
44+
45+
return ""
46+
>"" : ""
47+
> : ^^
48+
}
49+
3750
/** @type {function(function(): string): void} */
3851
const f = (p) => {}
3952
>f : (arg0: () => string) => void

Diff for: tests/cases/conformance/async/es2017/asyncArrowFunction/asyncArrowFunction_allowJs.ts

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ const c = async () => {
1818
return 0
1919
}
2020

21+
// Error (good)
22+
/** @type {function(): string} */
23+
const d = async () => {
24+
return ""
25+
}
26+
2127
/** @type {function(function(): string): void} */
2228
const f = (p) => {}
2329

0 commit comments

Comments
 (0)