Skip to content

Commit

Permalink
Add an extra test case for an error on async function typed using `@t…
Browse files Browse the repository at this point in the history
…ype` (#58217)
  • Loading branch information
Andarist committed Apr 20, 2024
1 parent b1d821a commit 21b5c96
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
13 changes: 11 additions & 2 deletions tests/baselines/reference/asyncArrowFunction_allowJs.errors.txt
Expand Up @@ -3,11 +3,12 @@ file.js(6,24): error TS1064: The return type of an async function or method must
file.js(7,23): error TS2322: Type 'number' is not assignable to type 'string'.
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>'?
file.js(12,2): error TS2322: Type 'number' is not assignable to type 'string'.
file.js(19,3): error TS2345: Argument of type '() => Promise<number>' is not assignable to parameter of type '() => string'.
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>'?
file.js(25,3): error TS2345: Argument of type '() => Promise<number>' is not assignable to parameter of type '() => string'.
Type 'Promise<number>' is not assignable to type 'string'.


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

// Error (good)
/** @type {function(): string} */
~~~~~~
!!! 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>'?
const d = async () => {
return ""
}

/** @type {function(function(): string): void} */
const f = (p) => {}

Expand Down
14 changes: 11 additions & 3 deletions tests/baselines/reference/asyncArrowFunction_allowJs.symbols
Expand Up @@ -19,14 +19,22 @@ const c = async () => {
return 0
}

// Error (good)
/** @type {function(): string} */
const d = async () => {
>d : Symbol(d, Decl(file.js, 16, 5))

return ""
}

/** @type {function(function(): string): void} */
const f = (p) => {}
>f : Symbol(f, Decl(file.js, 15, 5))
>p : Symbol(p, Decl(file.js, 15, 11))
>f : Symbol(f, Decl(file.js, 21, 5))
>p : Symbol(p, Decl(file.js, 21, 11))

// Error (good)
f(async () => {
>f : Symbol(f, Decl(file.js, 15, 5))
>f : Symbol(f, Decl(file.js, 21, 5))

return 0
})
13 changes: 13 additions & 0 deletions tests/baselines/reference/asyncArrowFunction_allowJs.types
Expand Up @@ -34,6 +34,19 @@ const c = async () => {
> : ^
}

// Error (good)
/** @type {function(): string} */
const d = async () => {
>d : () => string
> : ^^^^^^^^^^^^
>async () => { return ""} : () => string
> : ^^^^^^^^^^^^

return ""
>"" : ""
> : ^^
}

/** @type {function(function(): string): void} */
const f = (p) => {}
>f : (arg0: () => string) => void
Expand Down
Expand Up @@ -18,6 +18,12 @@ const c = async () => {
return 0
}

// Error (good)
/** @type {function(): string} */
const d = async () => {
return ""
}

/** @type {function(function(): string): void} */
const f = (p) => {}

Expand Down

0 comments on commit 21b5c96

Please sign in to comment.