|
1 | 1 | //// { compiler: { noImplicitAny: false }, order: 2 }
|
2 | 2 |
|
3 |
| -// With 3.7 TypeScript's existing 'infer from usage' |
4 |
| -// code fix became smarter. It will now use a list of |
5 |
| -// known important types (string, number, array, Promise) |
6 |
| -// and infer whether the usage of a type matches the API |
7 |
| -// of these objects. |
8 |
| - |
9 |
| -// For the next few examples, select the parameters of |
10 |
| -// the functions, click the light bulb and choose |
| 3 | +// Avec TypeScript 3.7 la correction automatique 'infer from usage' |
| 4 | +// s'améliore. Elle utilisera désormais une liste de types importants |
| 5 | +// (string, number, array, Promise) |
| 6 | +// et déduira si l'usage du type correspond a l'API de ces objets |
| 7 | + |
| 8 | +// Au sein des examples suivants, sélectionnez les paramètres des fonctions, |
| 9 | +// cliquez sur l'icône en forme d'ampoule et choisissez |
11 | 10 | // "Infer Parameter types..."
|
12 | 11 |
|
13 |
| -// Infer a number array: |
| 12 | +// Déduire une liste de nombres: |
14 | 13 |
|
15 | 14 | function pushNumber(arr) {
|
16 | 15 | arr.push(12);
|
17 | 16 | }
|
18 | 17 |
|
19 |
| -// Infer a promise: |
| 18 | +// Déduire une promesse: |
20 | 19 |
|
21 | 20 | function awaitPromise(promise) {
|
22 | 21 | promise.then((value) => console.log(value));
|
23 | 22 | }
|
24 | 23 |
|
25 |
| -// Infer the function, and its return type: |
| 24 | +// Déduire le type d'une fonction et son type de retour |
26 | 25 |
|
27 | 26 | function inferAny(app) {
|
28 | 27 | const result = app.use("hi");
|
29 | 28 | return result;
|
30 | 29 | }
|
31 | 30 |
|
32 |
| -// Infer a string array because a string |
33 |
| -// was added to it: |
| 31 | +// Déduire une liste de chaines de caractères, car une chaîne de caractères a été |
| 32 | +// ajoutée a cette liste: |
34 | 33 |
|
35 | 34 | function insertString(names) {
|
36 | 35 | names[1] = "hello";
|
|
0 commit comments