You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Change 1 means "I intend for`req.method`to always have the _literal type_`"GET"`", preventing the possible assignment of `"GUESS"`to that field after.
621
-
Change 2 means "I know for other reasons that`req.method`has the value`"GET"`".
620
+
Le premier changement signifie "Je veux que`req.method`ait toujours le type littéral `"GET"`", empêchant tout changement de cette valeur vers `"GUESS"`plus tard.
621
+
Le deuxième changement signifie "Je sais que, pour certaines raisons,`req.method`est égal à`"GET"`".
622
622
623
-
2.You can use`as const`to convert the entire object to be type literals:
@@ -629,86 +629,85 @@ Il y a deux façons de corriger ce problème.
629
629
handleRequest(req.url, req.method);
630
630
```
631
631
632
-
The `as const`suffix acts like `const`but for the type system, ensuring that all properties are assigned the literal type instead of a more general version like `string`or`number`.
632
+
Le suffixe `as const`vaut la même chose que `const`mais pour le système de types, garantissant que toutes les propriétés aient un type littéral, au lieu d'un type plus général comme `string`ou`number`.
633
633
634
-
## `null`and`undefined`
634
+
## `null`et`undefined`
635
635
636
-
JavaScript has two primitive values used to signal absent or uninitialized value: `null`and`undefined`.
636
+
JavaScript a deux valeurs primitives pour signaler une valeur inexistante ou non-initialisée : `null`et`undefined`.
637
637
638
-
TypeScript has two corresponding _types_by the same names. How these types behave depends on whether you have the[`strictNullChecks`](/tsconfig#strictNullChecks) option on.
638
+
TypeScript a deux _types_des mêmes noms. Le comportement de ces types dépend de l'activation de l'option[`strictNullChecks`](/tsconfig#strictNullChecks).
639
639
640
-
### `strictNullChecks`off
640
+
### `strictNullChecks`désactivé
641
641
642
-
With[`strictNullChecks`](/tsconfig#strictNullChecks)_off_, values that might be `null`or`undefined`can still be accessed normally, and the values`null`and`undefined`can be assigned to a property of any type.
643
-
This is similar to how languages without null checks (e.g. C#, Java) behave.
644
-
The lack of checking for these values tends to be a major source of bugs; we always recommend people turn [`strictNullChecks`](/tsconfig#strictNullChecks)on if it's practical to do so in their codebase.
642
+
Si[`strictNullChecks`](/tsconfig#strictNullChecks)est _désactivé_, les valeurs qui pourraient être `null`ou`undefined`peuvent toujours être lues, et les valeurs`null`et`undefined`peuvent être assignées à des variables de tous types.
643
+
Ce comportement est similaire aux langages qui n'ont pas de vérification pour `null` ou `undefined` (ex. Java ou C#).
644
+
Ne pas vérifier pour ces deux valeurs tend à être une source importante de bugs ; nous recommandons toujours d'activer [`strictNullChecks`](/tsconfig#strictNullChecks)s'il est pratique de le faire.
645
645
646
-
### `strictNullChecks`on
646
+
### `strictNullChecks`activé
647
647
648
-
With[`strictNullChecks`](/tsconfig#strictNullChecks)_on_, when a value is`null`or`undefined`, you will need to test for those values before using methods or properties on that value.
649
-
Just like checking for `undefined`before using an optional property, we can use _narrowing_ to check for values that might be `null`:
648
+
Si[`strictNullChecks`](/tsconfig#strictNullChecks)est _activé_, quand une valeur est`null`ou`undefined`, vous devrez vous assurer que ces deux types sont écartés avant d'utiliser des méthodes ou des propriétés sous ces valeurs.
649
+
Tout comme `undefined`doit être éliminé avant d'utiliser une propriété facultative, vous pouvez vous servir du _rétrécissement_ pour éliminer les valeurs qui pourraient être `null`:
650
650
651
651
```ts twoslash
652
652
function doSomething(x:string|null) {
653
653
if (x===null) {
654
-
//do nothing
654
+
//ne rien faire
655
655
} else {
656
-
console.log("Hello, "+x.toUpperCase());
656
+
console.log("Bonjour, "+x.toUpperCase());
657
657
}
658
658
}
659
659
```
660
660
661
-
### Non-null Assertion Operator (Postfix`!`)
661
+
### Opérateur d'assertion non-nulle (Suffixe`!`)
662
662
663
-
TypeScript also has a special syntax for removing `null`and`undefined`from a type without doing any explicit checking.
664
-
Writing`!`after any expression is effectively a type assertion that the value isn't `null` or`undefined`:
663
+
TypeScript possède une syntaxe spéciale pour éliminer `null`et`undefined`d'un type sans passer par un rétrécissement.
664
+
Écrire`!`après toute expression est effectivement une assertion que cette valeur n'est ni `null`, ni`undefined`:
665
665
666
666
```ts twoslash
667
667
function liveDangerously(x?:number|null) {
668
-
//No error
668
+
//Pas d'erreur
669
669
console.log(x!.toFixed());
670
670
}
671
671
```
672
672
673
-
Just like other type assertions, this doesn't change the runtime behavior of your code, so it's important to only use `!`when you know that the value _can't_ be `null`or`undefined`.
673
+
Tout comme les autres assertions, votre code ne sera pas changé à l'exécution, donc n'utilisez l'opérateur `!`que si vous savez que votre type _ne peut jamais_ être `null`ni`undefined`.
674
674
675
675
## Enums
676
676
677
-
Enums are a feature added to JavaScript by TypeScript which allows for describing a value which could be one of a set of possible named constants. Unlike most TypeScript features, this is _not_ a type-level addition to JavaScript but something added to the language and runtime. Because of this, it's a feature which you should know exists, but maybe hold off on using unless you are sure. You can read more about enums in the [Enum reference page](/docs/handbook/enums.html).
677
+
Les Enums sont une fonctionnalité ajoutée à JavaScript par TypeScript. Elle permet de décrire une valeur qui pourrait faire partie d'un ensemble de constantes nommées. Au contraire de la plupart des fonctionnalités TypeScript, elle n'est _pas_ un ajout au niveau du système de types, mais bel et bien un ajout qui sera reflété à l'exécution. De ce fait, vous devriez savoir que cette possibilité existe, mais vous ne devriez vous en servir que si vous en avez la certitude. Vous pouvez lire plus dans la [page de référence d'Enums](/fr/docs/handbook/enums.html).
678
678
679
-
## Less Common Primitives
679
+
## Primitives moins fréquentes
680
680
681
-
It's worth mentioning the rest of the primitives in JavaScript which are represented in the type system.
682
-
Though we will not go into depth here.
681
+
Il serait intéressant de mentionner le reste des primitives JavaScript représentées dans le système de types, bien que nous ne rentrerons pas dans leurs détails.
683
682
684
683
#### `bigint`
685
684
686
-
From ES2020 onwards, there is a primitive in JavaScript used for very large integers, `BigInt`:
685
+
À partir d'ES2020, il existe une primitive JavaScript pour les très grands entiers, `BigInt`:
687
686
688
687
```ts twoslash
689
688
// @target: es2020
690
689
691
-
//Creating a bigint via the BigInt function
690
+
//Création d'un BigInt via la fonction
692
691
const oneHundred:bigint=BigInt(100);
693
692
694
-
//Creating a BigInt via the literal syntax
693
+
//Création d'un BigInt via la syntaxe littérale
695
694
const anotherHundred:bigint=100n;
696
695
```
697
696
698
-
You can learn more about BigInt in [the TypeScript 3.2 release notes](/docs/handbook/release-notes/typescript-3-2.html#bigint).
697
+
Vous pouvez en apprendre plus sur les BigInt dans les [notes de changement de TypeScript 3.2](/docs/handbook/release-notes/typescript-3-2.html#bigint).
699
698
700
699
#### `symbol`
701
700
702
-
There is a primitive in JavaScript used to create a globally unique reference via the function`Symbol()`:
701
+
Il existe une primitive en JavaScript qui sert à créer des références uniques via la fonction`Symbol()`:
703
702
704
703
```ts twoslash
705
704
// @errors: 2367
706
-
const firstName =Symbol("name");
707
-
const secondName =Symbol("name");
705
+
const firstName =Symbol("nom");
706
+
const secondName =Symbol("nom");
708
707
709
708
if (firstName===secondName) {
710
-
//Can't ever happen
709
+
//Ne peut jamais se produire
711
710
}
712
711
```
713
712
714
-
You can learn more about them in [Symbols reference page](/docs/handbook/symbols.html).
713
+
Vous pouvez en savoir plus dans la [page de référence des Symbols](/fr/docs/handbook/symbols.html).
0 commit comments