Skip to content

Commit aff2325

Browse files
committed
TSConfig Italian translation: added allowSyntheticDefaultImports.md
1 parent 73e6f15 commit aff2325

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
display: "Permetti Import Sintetici Predefiniti"
3+
oneline: "Permette di importare un modulo x da un modulo y’ quando un modulo non ha un’esportazione standard."
4+
---
5+
6+
Quando è impostato a true, `allowSyntheticDefaultImports` permette di scrivere un import così:
7+
8+
```ts
9+
import React from "react";
10+
```
11+
12+
Al posto di:
13+
14+
```ts
15+
import * as React from "react";
16+
```
17+
18+
Quando un modulo **non** specifica esplicitamente un export predefinito.
19+
20+
Per esempio, senza `allowSyntheticDefaultImports` impostato a true:
21+
22+
```ts twoslash
23+
// @errors: 1259 1192
24+
// @checkJs
25+
// @allowJs
26+
// @esModuleInterop: false
27+
// @filename: utilFunctions.js
28+
// @noImplicitAny: false
29+
const getStringLength = (str) => str.length;
30+
31+
module.exports = {
32+
getStringLength,
33+
};
34+
35+
// @filename: index.ts
36+
import utils from "./utilFunctions";
37+
38+
const count = utils.getStringLength("Check JS");
39+
```
40+
41+
Questo codice segnala un errore perché un oggetto `default` che puoi importare non è presente.Anche se sembra che dovrebbe esserci. Per convenienza, se un oggetto `default` non è presente un transpiler come Babel automaticamente lo creerà.
42+
43+
```ts
44+
// @filename: utilFunctions.js
45+
const getStringLength = (str) => str.length;
46+
const allFunctions = {
47+
getStringLength,
48+
};
49+
50+
module.exports = allFunctions;
51+
module.exports.default = allFunctions;
52+
```
53+
54+
Questo flag non apporta cambiamenti al JavaScript emesso da TypeScript, è solo per controllare il tipo. Questa opzione porta il comportamento di TypeScript in linea con Babel emettendo un codice extra in modo di rendere l'uso di un export predefinito più ergonomico.

0 commit comments

Comments
 (0)