Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf4f8533

Browse files
docs: clarify type checking for template literals .each syntax
1 parent9969aed commitf4f8533

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎docs/GlobalAPI.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,3 +1094,23 @@ test.each<{a: number; b: number; expected: string; extra?: boolean}>`
10941094
// all arguments are typed as expected, e.g. `a: number`, `expected: string`, `extra: boolean | undefined`
10951095
});
10961096
```
1097+
1098+
:::caution
1099+
1100+
Keep in mind the variables inside the template literal are not type checked, so you have to ensure that their types are correct.
1101+
1102+
```ts
1103+
import {test}from'@jest/globals';
1104+
1105+
test.each<{a:number; expected:string}>`
1106+
a | expected
1107+
${1} | ${'one'}
1108+
${'will not raise TS error'} | ${'two'}
1109+
${3} | ${'three'}
1110+
`('template literal with wrongly typed input', ({a,expected})=> {
1111+
// all arguments are typed as stated in the generic: `a: number`, `expected: string`
1112+
// WARNING: `a` is of type `number` but will be a string in the 2nd test case.
1113+
});
1114+
```
1115+
1116+
:::

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp