Skip to content

Commit bd23117

Browse files
author
mk360
committed
finish conditional types, fix build
1 parent 245fcc1 commit bd23117

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

docs/documentation/fr/handbook-v2/Object Types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Object Types
33
layout: docs
4-
permalink: /docs/handbook/2/objects.html
4+
permalink: /fr/docs/handbook/2/objects.html
55
oneline: "How TypeScript describes the shapes of JavaScript objects."
66
---
77

docs/documentation/fr/handbook-v2/Type Manipulation/Conditional Types.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Types Conditionnels
33
layout: docs
4-
permalink: /docs/fr/handbook/2/conditional-types.html
4+
permalink: /fr/docs/handbook/2/conditional-types.html
55
oneline: "Créer des types qui agissent comme des déclarations if dans le système de typage."
66
---
77

@@ -187,8 +187,8 @@ type Flatten<Type> = Type extends Array<infer Item> ? Item : Type;
187187
Ici, le mot-clé `infer` introduit un nouveau type générique variable appelé `Item`, au lieu de préciser comment récupérer le type élément de `T` dans la branche vrai.
188188
Cela nous libère de devoir penser à la façon de creuser et obtenir manuellement les types qui nous intéressent.
189189

190-
We can write some useful helper type aliases using the `infer` keyword.
191-
For example, for simple cases, we can extract the return type out from function types:
190+
Nous pouvons écrire des types utiles grâce au mot-clé `infer`.
191+
Pour les cas simples, il est possible d'inférer le type de retour d'une fonction :
192192

193193
```ts twoslash
194194
type GetReturnType<Type> = Type extends (...args: never[]) => infer Return
@@ -205,7 +205,7 @@ type Bools = GetReturnType<(a: boolean, b: boolean) => boolean[]>;
205205
// ^?
206206
```
207207

208-
When inferring from a type with multiple call signatures (such as the type of an overloaded function), inferences are made from the _last_ signature (which, presumably, is the most permissive catch-all case). It is not possible to perform overload resolution based on a list of argument types.
208+
Lorsqu'on infère depuis une fonction qui a plusieurs signatures, le résultat est l'inférence de la _dernière_ (et donc probablement la plus laxiste). Il n'est pas possible d'inférer une signature particulière en se basant sur une liste d'arguments de types.
209209

210210
```ts twoslash
211211
declare function stringOrNum(x: string): number;
@@ -216,16 +216,16 @@ type T1 = ReturnType<typeof stringOrNum>;
216216
// ^?
217217
```
218218

219-
## Distributive Conditional Types
219+
## Types Conditionnels Distributifs
220220

221-
When conditional types act on a generic type, they become _distributive_ when given a union type.
222-
For example, take the following:
221+
Quand les types conditionnels opèrent sur un type générique, ils deviennent _distributifs_ quand on utilise également un type union.
222+
Par exemple :
223223

224224
```ts twoslash
225225
type ToArray<Type> = Type extends any ? Type[] : never;
226226
```
227227

228-
If we plug a union type into `ToArray`, then the conditional type will be applied to each member of that union.
228+
Si `ToArray` reçoit un type union, le type conditionnel va s'appliquer sur chaque membre de ce type union.
229229

230230
```ts twoslash
231231
type ToArray<Type> = Type extends any ? Type[] : never;
@@ -234,15 +234,15 @@ type StrArrOrNumArr = ToArray<string | number>;
234234
// ^?
235235
```
236236

237-
What happens here is that `StrArrOrNumArr ` distributes on:
237+
`StrArrOrNumArr ` se distribue sur :
238238

239239
```ts twoslash
240240
type StrArrOrNumArr =
241241
// ---cut---
242242
string | number;
243243
```
244244

245-
and maps over each member type of the union, to what is effectively:
245+
et s'applique à chaque membre de l'union, ce qui donne :
246246

247247
```ts twoslash
248248
type ToArray<Type> = Type extends any ? Type[] : never;
@@ -251,16 +251,16 @@ type StrArrOrNumArr =
251251
ToArray<string> | ToArray<number>;
252252
```
253253

254-
which leaves us with:
254+
En suivant la logique de `ToArray` avec `string` et `number`, on finit par obtenir :
255255

256256
```ts twoslash
257257
type StrArrOrNumArr =
258258
// ---cut---
259259
string[] | number[];
260260
```
261261

262-
Typically, distributivity is the desired behavior.
263-
To avoid that behavior, you can surround each side of the `extends` keyword with square brackets.
262+
La distributivité est le comportement voulu d'habitude.
263+
Pour éviter ce comportement, vous pouvez entourer chaque côté du mot-clé `extends` avec des crochets.
264264

265265
```ts twoslash
266266
type ToArrayNonDist<Type> = [Type] extends [any] ? Type[] : never;

0 commit comments

Comments
 (0)