Skip to content

Commit 0bc5461

Browse files
author
Orta Therox
authored
Merge pull request #19 from Nabster101/main
TSConfig Italian translation: added various files
2 parents a7d0294 + d4867f1 commit 0bc5461

File tree

3 files changed

+301
-0
lines changed

3 files changed

+301
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
display: "Iterazione di livello inferiore"
3+
oneline: "Emette Javascript compatibile e più dettagliato per oggetti iterativi"
4+
---
5+
6+
Iterazione di livello inferiore, o Downleveling, è un termine di TypeScript utilizzato per migrare verso una versione precedente di JavaScript. Questa flag permette quindi di supportare una più accurata implementazione di come il JavaScript moderno itera i nuovi concetti in versioni precedenti di JavaScript in runtime.
7+
8+
ECMAScript 6 aggiunge una serie di nuove iterazioni primitive: il `for / of` loop (`for (el of arr)`), spread di Array (`[a, ...b]`), spread di argomenti (`fn (... args)`) e [`Symbol.iterator`](https://medium.com/trainingcenter/iterators-em-javascript-880adef14495).`--downlevelIteration` permette a queste iterazioni primitive di essere utilizzate in modo più accurrato in un ambiente ES5 se un'implementazione di [`Symbol.iterator`](https://medium.com/trainingcenter/iterators-em-javascript-880adef14495) è presente.
9+
10+
#### Esempio: Effetti su `for / of`
11+
12+
Con questo codice TypeScript:
13+
14+
```js
15+
const str = "Ciao!";
16+
for (const s of str) {
17+
console.log(s);
18+
}
19+
```
20+
21+
Senza `downlevelIteration` attivo, un loop `for / of` su un qualsiasi oggetto viene convertito in un tradizionale `for` loop:
22+
23+
```ts twoslash
24+
// @target: ES5
25+
// @showEmit
26+
const str = "Ciao!";
27+
for (const s of str) {
28+
console.log(s);
29+
}
30+
```
31+
32+
Generalmente tutti si aspettano questo, tuttavia non è compatibile al 100% con il protocollo di iterazione ECMAScript 6. Certe string, ad esempio un emoji (😜), hanno un `.length` di 2 (o anche di più!), ma dovrebbero iterare come 1 unità in un `for-of` loop. Guarda [questo blog post di Jonathan New](https://blog.jonnew.com/posts/poo-dot-length-equals-two) per una spiegazione più dettagliata.
33+
34+
Quando `downlevelIteration` è attivo, TypeScript utilizzerà una funzione ausiliaria che andrà a controllare la presenza di un `Symbol.iterator` (che può essere di tipo nativo o polyfill). Nel caso in cui questa implementazione non ci sia, ritornerai ad un'iterazione index-based.
35+
36+
```ts twoslash
37+
// @target: ES5
38+
// @downlevelIteration
39+
// @showEmit
40+
const str = "Ciao!";
41+
for (const s of str) {
42+
console.log(s);
43+
}
44+
```
45+
46+
Puoi utilizzare [tslib](https://www.npmjs.com/package/tslib) via [importHelpers](#importHelpers) in modo da ridurre il numero di righe inline Javascript:
47+
48+
```ts twoslash
49+
// @target: ES5
50+
// @downlevelIteration
51+
// @importHelpers
52+
// @showEmit
53+
const str = "Ciao!";
54+
for (const s of str) {
55+
console.log(s);
56+
}
57+
```
58+
59+
> > **Nota:** attivare `downlevelIteration` non andrà a migliorare le prestazioni di compliazione se `Symbol.iterator` non è presente in runtime.
60+
61+
#### Esempio: Effetti sullo spray di Array
62+
63+
Questo è un spread di array:
64+
65+
```js
66+
// Crea un nuovo array composto dall'elemento 1 seguito dagli elementi di arr2
67+
const arr = [1, ...arr2];
68+
```
69+
70+
Secondo la descrizione, sembra facile convertirlo in ES5:
71+
72+
```js
73+
// Stessa cosa, no?
74+
const arr = [1].concat(arr2);
75+
```
76+
77+
Tuttavia, questo è visibilmente diverso in certi rari casi. Ad esempio, nel caso un array abbia un "buco", l'index mancante andrà a creare una proprietà *own* nel caso si decida di applicare uno spread, ma non se creato utilizzando `.concat`:
78+
79+
```js
80+
// Crea un array dove manca l'elemento '1'
81+
let mancante = [0, , 1];
82+
let spread = [...mancante];
83+
let concatenato = [].concat(mancante);
84+
85+
// true
86+
"1" in spread;
87+
// false
88+
"1" in concatenato;
89+
```
90+
91+
Proprio come un `for / of`, `downlevelIteration` andrà ad usare `Symbol.iterator` (se presente) in modo da emulare in modo più preciso il comportamento di ES 6.

docs/tsconfig/it/options/jsx.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
display: "JSX"
3+
oneline: "Controlla come viene emesso JSX"
4+
---
5+
6+
Controlla come i costrutti JSX vengono emessi in file Javascript. Questo influisce sull'output solo nel caso il file JS termini con `.tsx`.
7+
8+
- `react`: Genera dei file `.js` con JSX modificato nelle chiamate `React.createElements` equivalenti.
9+
- `react-jsx`: Genera dei file `.js` con JSX modificato nelle chiamate `_jsx`.
10+
- `react-jsxdev`: Genera dei file `.js` con JSX modificato in chiamate `_jsx`.
11+
- `preserve`: Genera dei file `.jsx` con JSX invariato.
12+
- `react-native`: Genera dei file `.js` con JSX invariato.
13+
14+
### Per esempio
15+
16+
Questo codice esempio:
17+
18+
```tsx
19+
export const ciaoMondo = () => <h1>Ciao mondo</h1>;
20+
```
21+
22+
Predefinito: `"react"`
23+
24+
```tsx twoslash
25+
declare module JSX {
26+
interface Element {}
27+
interface IntrinsicElements {
28+
[s: string]: any;
29+
}
30+
}
31+
// @showEmit
32+
// @noErrors
33+
export const ciaoMondo = () => <h1>Ciao mondo</h1>;
34+
```
35+
36+
Conservare: `"preserve"`
37+
38+
```tsx twoslash
39+
declare module JSX {
40+
interface Element {}
41+
interface IntrinsicElements {
42+
[s: string]: any;
43+
}
44+
}
45+
// @showEmit
46+
// @noErrors
47+
// @jsx: preserve
48+
export const ciaoMondo = () => <h1>Ciao mondo</h1>;
49+
```
50+
51+
React Native: `"react-native"`
52+
53+
```tsx twoslash
54+
declare module JSX {
55+
interface Element {}
56+
interface IntrinsicElements {
57+
[s: string]: any;
58+
}
59+
}
60+
// @showEmit
61+
// @noErrors
62+
// @jsx: react-native
63+
export const ciaoMondo = () => <h1>Ciao mondo</h1>;
64+
```
65+
66+
React 17 convertito: `"react-jsx"`<sup>[[1]](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)</sup>
67+
68+
```tsx twoslash
69+
declare module JSX {
70+
interface Element {}
71+
interface IntrinsicElements {
72+
[s: string]: any;
73+
}
74+
}
75+
// @showEmit
76+
// @noErrors
77+
// @jsx: react-jsx
78+
export const ciaoMondo = () => <h1>Ciao mondo</h1>;
79+
```
80+
81+
React 17 dev convertito: `"react-jsxdev"`<sup>[[1]](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)</sup>
82+
83+
```tsx twoslash
84+
declare module JSX {
85+
interface Element {}
86+
interface IntrinsicElements {
87+
[s: string]: any;
88+
}
89+
}
90+
// @showEmit
91+
// @noErrors
92+
// @jsx: react-jsxdev
93+
export const ciaoMondo = () => <h1>Ciao mondo</h1>;
94+
```

docs/tsconfig/it/options/module.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
display: "Modulo"
3+
oneline: "Definisce il sistema di moduli previsto per il runtime"
4+
---
5+
6+
Definisce il sistema di moduli per il programma. Consulta la sezione <a href='/docs/handbook/modules.html#ambient-modules'> Moduli </a> per più informazioni. Per i progetti che utilizzano node è probabile che tu voglia `"CommonJS"`.
7+
8+
Questo è un output di esempio:
9+
10+
```ts twoslash
11+
// @filename: costanti.ts
12+
export const valoreDiPi = 3.142;
13+
// ---cut---
14+
// @filename: index.ts
15+
import { valoreDiPi } from "./costanti";
16+
17+
export const doppioPi = valoreDiPi * 2;
18+
```
19+
20+
#### `CommonJS`
21+
22+
```ts twoslash
23+
// @showEmit
24+
// @module: commonjs
25+
// @filename: costanti.ts
26+
export const valoreDiPi = 3.142;
27+
// @filename: index.ts
28+
// ---cut---
29+
import { valoreDiPi } from "./costanti";
30+
31+
export const doppioPi = valoreDiPi * 2;
32+
```
33+
34+
#### `UMD`
35+
36+
```ts twoslash
37+
// @showEmit
38+
// @module: umd
39+
// @filename: costanti.ts
40+
export const valoreDiPi = 3.142;
41+
// ---cut---
42+
// @filename: index.ts
43+
import { valoreDiPi } from "./costanti";
44+
45+
export const doppioPi = valoreDiPi * 2;
46+
```
47+
48+
#### `AMD`
49+
50+
```ts twoslash
51+
// @showEmit
52+
// @module: amd
53+
// @filename: costanti.ts
54+
export const valoreDiPi = 3.142;
55+
// ---cut---
56+
// @filename: index.ts
57+
import { valoreDiPi } from "./costanti";
58+
59+
export const doppioPi = valoreDiPi * 2;
60+
```
61+
62+
#### `System`
63+
64+
```ts twoslash
65+
// @showEmit
66+
// @module: system
67+
// @filename: costanti.ts
68+
export const valoreDiPi = 3.142;
69+
// ---cut---
70+
// @filename: index.ts
71+
import { valoreDiPi } from "./costanti";
72+
73+
export const doppioPi = valoreDiPi * 2;
74+
```
75+
76+
#### `ESNext`
77+
78+
```ts twoslash
79+
// @showEmit
80+
// @module: esnext
81+
// @filename: costanti.ts
82+
export const valoreDiPi = 3.142;
83+
// ---cut---
84+
// @filename: index.ts
85+
import { valoreDiPi } from "./costanti";
86+
87+
export const doppioPi = valoreDiPi * 2;
88+
```
89+
90+
#### `ES2020`
91+
92+
```ts twoslash
93+
// @showEmit
94+
// @module: es2020
95+
// @filename: costanti.ts
96+
export const valoreDiPi = 3.142;
97+
// ---cut---
98+
// @filename: index.ts
99+
import { valoreDiPi } from "./costanti";
100+
101+
export const doppioPi = valoreDiPi * 2;
102+
```
103+
104+
### `None`
105+
106+
```ts twoslash
107+
// @showEmit
108+
// @module: none
109+
// @filename: costanti.ts
110+
export const valoreDiPi = 3.142;
111+
// ---cut---
112+
// @filename: index.ts
113+
import { valoreDiPi } from "./costanti";
114+
115+
export const doppioPi = valoreDiPi * 2;
116+
```

0 commit comments

Comments
 (0)