Starting up are the root options in the TSConfig - these options relate to how your TypeScript or JavaScript project is set up.
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } } Menentukan daftar berkas yang diijinkan untuk disertakan dalam program. Kesalahan terjadi jika salah satu berkas tidak dapat ditemukan. { "compilerOptions": {}, "files": [ "core.ts", "sys.ts", "types.ts", "scanner.ts", "parser.ts", "utilities.ts", "binder.ts", "checker.ts", "tsc.ts" ] } Ini berguna ketika Anda hanya memiliki sejumlah berkas kecil dan tidak perlu menggunakan glob untuk mereferensikan banyak berkas. Jika Anda membutuhkannya, gunakan . { "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } } Files -
60
62
Extends - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
65
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Nilai
65 adalah string yang berisi jalur ke berkas konfigurasi lain untuk mewarisi. Jalur tersebut mungkin menggunakan resolusi gaya Node.js.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Konfigurasi dari berkas dasar dimuat terlebih dahulu, kemudian diganti dengan yang ada di berkas konfigurasi pewarisan. Semua jalur relatif yang ditemukan di berkas konfigurasi akan diselesaikan secara relatif terhadap berkas konfigurasi tempat asalnya.
Perlu diperhatikan bahwa
60,
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
61 dan
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
64 dari berkas konfigurasi pewaris menimpa konfigurasi yang berasal dari berkas konfigurasi asal, dan sirkularitas antara berkas konfigurasi tidak diperbolehkan.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Saat ini, satu-satunya properti tingkat atas yang dikecualikan dari pewarisan adalah .
Contoh
71:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
72:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
73:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
Properti dengan jalur relatif yang ditemukan di berkas konfigurasi, yang tidak dikecualikan dari pewarisan, akan diresolusikan secara relatif terhadap berkas konfigurasi tempat asalnya.
- Default:
62{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Released:
2.1
Disertakan [_Include_] - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
61
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Menentukan sebuah susunan nama berkas atau contoh berkas untuk dimasukkan ke dalam program. Nama berkas ini diselesaikan dengan direktori yang berisi berkas
72.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
json
{
"include": ["src/**/*", "tests/**/*"]
}
Yang akan mencakup:
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
61 dan
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
64 mendukung karakter untuk membuat pola global:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
79 cocok dengan nol atau lebih karakter [tidak termasuk pemisah direktori]{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
80 cocok dengan salah satu karakter [tidak termasuk pemisah direktori]{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
81 cocok dengan direktori apa pun yang bertingkat.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Jika contoh umum tidak menyertakan ekstensi berkas, maka hanya berkas dengan ekstensi yang didukung yang disertakan [misalnya
82,
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
83, dan
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
84 secara default, dengan
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
85 dan
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
86 jika
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
87 disetel ke true].
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Default:
88 if is specified,,{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
90 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
2.0
Exclude - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
64
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Menentukan array nama berkas atau pola yang harus dilewati saat menyelesaikan
61.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Penting:
64 hanya mengubah berkas mana yang disertakan sebagai hasil dari pengaturan
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
61. Berkas yang ditentukan oleh
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
64 masih bisa menjadi bagian dari basis kode Anda karena pernyataan
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
98 dalam kode Anda, penyertaan
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
99, perintah
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
00, atau ditentukan dalam daftar
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
60.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Ini bukan mekanisme yang mencegah berkas untuk disertakan dalam basis kode - ini hanya mengubah apa yang ditemukan oleh setelan
61.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Default:
node_modules,bower_components,jspm_packages,
- Related:
Referensi - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
06
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
Referensi proyek adalah cara untuk menyusun program TypeScript Anda menjadi bagian-bagian yang lebih kecil. Menggunakan Referensi Proyek dapat sangat meningkatkan waktu interaksi build dan editor, menerapkan pemisahan logika antar komponen, dan mengatur kode Anda dengan cara yang baru dan lebih baik.
Anda dapat membaca lebih lanjut tentang bagaimana cara kerja referensi di bagian Referensi Proyek dari buku pegangan
- Default:
62{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Pilihan - Pilihan Kompiler
Banyak pilihan yang membuat jumlah besar di pengaturan Typescript’s dan itu juga meliputi bagaimana bahasa seharusnya bekerja.
Type Checking
Izinkan Kode Tak Terjangkau - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
08
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
Kapan:
09 default memberikan saran sebagai peringatan kepada editor{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
10 kode yang tidak dapat dijangkau diabaikan{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62 menimbulkan galat kompiler tentang kode yang tidak dapat dijangkau{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Peringatan ini hanya tentang kode yang terbukti tidak dapat dijangkau karena penggunaan sintaks JavaScript, misalnya:
ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Dengan
12:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Ini tidak mempengaruhi galat atas dasar kode yang muncul menjadi tidak dapat dijangkau karena menggolongkan uraian.
- Released:
1.8
Izinkan Label yang Tidak Digunakan - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
13
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
Setel ke false untuk menonaktifkan peringatan tentang label yang tidak digunakan.
Label sangat jarang di JavaScript dan biasanya menunjukkan upaya untuk menulis objek dengan tepat:
ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
- Released:
1.8
Selalu Tepat - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
14
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
Pastikan bahwa berkas Anda diurai di Mode strict EcmaScript, dan mengeluarkan “use strict” untuk setiap berkas asal.
ECMAScript strict mode strict diperkenalkan di ES5 dan memberikan perubahan perilaku pada waktu proses mesin JavaScript untuk meningkatkan kinerja dan membuat kesalahan muncul agar diabaikan.
- Recommended
- Default:
10 if ,,{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
2.1
exactOptionalPropertyTypes - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
19
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
With exactOptionalPropertyTypes enabled, TypeScript applies stricter rules around how it handles properties on
20 or
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
21 which have a
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
80 prefix.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
For example, this interface declares that there is a property which can be one of two strings: ‘dark’ or ‘light’ or it should not be in the object.
ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
Without this flag enabled, there are three values which you can set
23 to be: “dark”, “light” and
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
09.
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
Setting the value to
09 will allow most JavaScript runtime checks for the existence to fail, which is effectively falsy. However, this isn’t quite accurate
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
26 is not the same as
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
23 not being defined. For example
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
28 would have different behavior with
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
09 as the key compared to not being defined.
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
19 makes TypeScript truly enforce the definition provided as an optional property:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
0
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Recommended
- Released:
4.4
No Fallthrough Cases In Switch - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
31
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
Report errors for fallthrough cases in switch statements. Ensures that any non-empty case inside a switch statement includes either
32 or
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
33. This means you won’t accidentally ship a case fallthrough bug.
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
1
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Released:
1.8
No Implicit Any - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
34
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
Di beberapa kasus, dimana tidak ada anotasi tipe yang ada, TypeScript akan kembali ke suatu tipe dari
35 untuk suatu variabel yang saat itu tidakbisa simpulkan tipenya.
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
Ini dapat menyebabkan beberapa kesalahan untuk dilewatkan, sebagai contoh:
2
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Menyalakan opsi
34 namun TypeScript akan mengeluarkan kesalahan setiap kali
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
35 yang ia simpulkan:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
3
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Recommended
- Default:
10 if ,,{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
noImplicitOverride - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
42
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
When working with classes which use inheritance, it’s possible for a sub-class to get “out of sync” with the functions it overloads when they are renamed in the base class.
For example, imagine you are modeling a music album syncing system:
4
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Then when you add support for machine-learning generated playlists, you refactor the
43 class to have a ‘setup’ function instead:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
5
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
In this case, TypeScript has provided no warning that
44 on
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
45 expected to override a function in the base class.
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
Using
42 you can ensure that the sub-classes never go out of sync, by ensuring that functions which override include the keyword
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
47.
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
The following example has
42 enabled, and you can see the error received when
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
47 is missing:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
6
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Released:
4.3
No Implicit Returns - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
50
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
Saat diaktifkaan, TypeScript akan melakukan pengecekan semua jalur kode di suatu fungsi untuk memastikan mereka mengembalikan suatu nilai.
7
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Released:
1.8
No Implicit This - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
51
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
Menimbulkan kesalahan kepada pernyataan ‘this’ dengan tersiratnya tipe ‘any’.
Sebagai contoh, class dibawah ini mengembalikan suatu fungsi yang mencoba mengakses
52 dan
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
53 – tapi konteksnya untuk
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
54 didalam fungsi yang didalam
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
55 ini, bukanlah instansi dari class Rectangle.
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
8
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Recommended
- Default:
10 if ,,{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
2.0
noPropertyAccessFromIndexSignature - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
60
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
This setting ensures consistency between accessing a field via the “dot” [
61] syntax, and “indexed” [
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62] and the way which the property is declared in the type.
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
Without this flag, TypeScript will allow you to use the dot syntax to access fields which are not defined:
9
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Turning the flag on will raise an error because the unknown field uses dot syntax instead of indexed syntax.
0
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
The goal of this flag is to signal intent in your calling syntax about how certain you are this property exists.
- Released:
4.2
noUncheckedIndexedAccess - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
63
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
TypeScript has a way to describe objects which have unknown keys but known values on an object, via index signatures.
1
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
Turning on
63 will add
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
09 to any un-declared field in the type.
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
2
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
- Released:
4.1
No Unused Locals - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
66
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
Report errors on unused local variables.
3
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
- Released:
2.0
No Unused Parameters - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
67
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
Report errors on unused parameters in functions.
4
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
- Released:
2.0
Strict - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
16
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
The
16 flag enables a wide range of type checking behavior that results in stronger guarantees of program correctness. Turning this on is equivalent to enabling all of the strict mode family options, which are outlined below. You can then turn off individual strict mode family checks as needed.
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
Future versions of TypeScript may introduce additional stricter checking under this flag, so upgrades of TypeScript might result in new type errors in your program. When appropriate and possible, a corresponding flag will be added to disable that behavior.
- Recommended
- Related:
- Released:
2.3
Strict Bind Call Apply - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
72
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
When set, TypeScript will check that the built-in methods of functions
79,
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
80, and
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
81 are invoked with correct argument for the underlying function:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
5
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
Otherwise, these functions accept any arguments and will return
35:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
6
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
- Recommended
- Default:
10 if ,,{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
3.2
Strict Function Types - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
73
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
When enabled, this flag causes functions parameters to be checked more correctly.
Here’s a basic example with
73 off:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
7
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
With
73 on, the error is correctly detected:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
8
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
During development of this feature, we discovered a large number of inherently unsafe class hierarchies, including some in the DOM. Because of this, the setting only applies to functions written in function syntax, not to those in method syntax:
9
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
- Recommended
- Default:
10 if ,,{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
2.6
Strict Null Checks - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
71
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
When
71 is
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62,
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
97 and
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
09 are effectively ignored by the language. This can lead to unexpected errors at runtime.
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
When
71 is
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
10,
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
97 and
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
09 have their own distinct types and you’ll get a type error if you try to use them where a concrete value is expected.
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
For example with this TypeScript code,
03 has no guarantee that it will actually find a user, but you can write code as though it will:
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
0
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
Setting
71 to
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
10 will raise an error that you have not made a guarantee that the
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
06 exists before trying to use it.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
1
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
The second example failed because the array’s
07 function looks a bit like this simplification:
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
2
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
- Recommended
- Default:
10 if ,,{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
2.0
Strict Property Initialization - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
74
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
When set to true, TypeScript will raise an error when a class property was declared but not set in the constructor.
3
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
In the above case:
13 is set specifically.{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
14 is set by default.{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
15 is not set and raises an error.{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
16 is declared as potentially{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
09 which means it does not have to be set.{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
- Recommended
- Default:
10 if ,,{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
2.7
useUnknownInCatchVariables - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
77
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
In TypeScript 4.0, support was added to allow changing the type of the variable in a catch clause from
35 to
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
24. Allowing for code like:
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
4
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
This pattern ensures that error handling code becomes more comprehensive because you cannot guarantee that the object being thrown is a Error subclass ahead of time. With the flag
77 enabled, then you do not need the additional syntax [
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
26] nor a linter rule to try enforce this behavior.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
- Default:
10 if ,,{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
4.4
Modules
Izinkan Akses Global Umd - {
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
31
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
Jika disetel ke true,
31 memungkinkan Anda mengakses ekspor UMD sebagai global dari dalam berkas modul. Berkas modul adalah berkas yang telah diimpor dan/atau diekspor. Tanpa opsi ini, menggunakan ekspor dari modul UMD memerlukan deklarasi impor.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
Contoh kasus penggunaan untuk opsi ini adalah proyek web yang anda tahu bahwa pustaka tertentu [seperti jQuery atau Lodash] akan selalu tersedia saat runtime, tetapi Anda tidak dapat mengaksesnya dengan impor.
- Released:
3.5
Base Url - {
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
33
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
Memungkinkan Anda menyetel direktori dasar untuk menyelesaikan nama modul dengan benar.
Anda dapat menentukan folder root di mana Anda dapat melakukan keputusan berkas yang sesungguhnya, misalnya :
5
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
Dengan
34 di dalam proyek ini TypeScript akan mencari berkas yang dimulai dari folder yang sama dengan
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
72.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
6
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
Jika Anda lelah cara impor selalu seperti
36 atau
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
37. Atau harus untuk merubah saat Anda memindahkan berkas, ini adalah cara terbaik untuk memperbaikinya.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
Module - {
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
38
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
Sets the module system for the program. See the Modules reference page for more information. You very likely want
39 for node projects.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
Changing
38 affects which also has a reference page.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
Here’s some example output for this file:
7
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
42
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
8
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
43
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
9
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
44
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
0json
{
"include": ["src/**/*", "tests/**/*"]
}
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
45
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
1json
{
"include": ["src/**/*", "tests/**/*"]
}
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
46
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
2json
{
"include": ["src/**/*", "tests/**/*"]
}
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
47
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
3json
{
"include": ["src/**/*", "tests/**/*"]
}
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
48/{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
49
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
4json
{
"include": ["src/**/*", "tests/**/*"]
}
If you are wondering about the difference between
48 [aka
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
49] and
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
47,
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
47 adds support for dynamic
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
98s, and
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
55.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
56/{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
57 [nightly builds]
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
Available from 4.7+, the
56 and
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
57 modes integrate with Node’s native ECMAScript Module support. The emitted JavaScript uses either
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
42 or
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
47 output depending on the file extension and the value of the
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
20 setting in the nearest
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
63. Module resolution also works differently. You can learn more in the handbook.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
64
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
5json
{
"include": ["src/**/*", "tests/**/*"]
}
- Default:
42 if is{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
67 or{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
68,,{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
49/{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
48 otherwise.{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
- Allowed:
71{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
72{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
73{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
74{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
75{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
76/{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
77{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
78{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
79{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
80{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
56{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
57{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
- Related:
- Released:
1.0
Module Resolution - {
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
41
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
Specify the module resolution strategy:
85 for Node.js’ CommonJS implementation{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
86 or{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
87 for Node.js’ ECMAScript Module Support{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
88 used in TypeScript before the release of 1.6. You probably won’t need to use{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
89 in modern code{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
There is a handbook reference page on Module Resolution
- Default:
90 if is{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
44,{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
43,{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
45 or{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
49/{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
48,,Matches if is{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
98 or{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
57,,{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
00 otherwise.json
{
"include": ["src/**/*", "tests/**/*"]
}
- Allowed:
89{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
02json
{
"include": ["src/**/*", "tests/**/*"]
}
56{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
57{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
- Related:
moduleSuffixes - json
{
"include": ["src/**/*", "tests/**/*"]
}
06
json
{ "include": ["src/**/*", "tests/**/*"] }
Provides a way to override the default list of file name suffixes to search when resolving a module.
6json
{
"include": ["src/**/*", "tests/**/*"]
}
Given the above configuration, an import like the following:
7json
{
"include": ["src/**/*", "tests/**/*"]
}
TypeScript will look for the relative files
07,json
{
"include": ["src/**/*", "tests/**/*"]
}
08, and finallyjson
{
"include": ["src/**/*", "tests/**/*"]
}
09.json
{
"include": ["src/**/*", "tests/**/*"]
}
Note the empty string
10 in which is necessary for TypeScript to also look-upjson
{
"include": ["src/**/*", "tests/**/*"]
}
09.json
{
"include": ["src/**/*", "tests/**/*"]
}
This feature can be useful for React Native projects where each target platform can use a separate tsconfig.json with differing
06.json
{
"include": ["src/**/*", "tests/**/*"]
}
- Released:
4.7
No Resolve - json
{
"include": ["src/**/*", "tests/**/*"]
}
14
json
{ "include": ["src/**/*", "tests/**/*"] }
By default, TypeScript will examine the initial set of files for
98 and
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
16 directives and add these resolved files to your program.json
{
"include": ["src/**/*", "tests/**/*"]
}
If
14 is set, this process doesn’t happen. However,json
{
"include": ["src/**/*", "tests/**/*"]
}
98 statements are still checked to see if they resolve to a valid module, so you’ll need to make sure this is satisfied by some other means.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Paths - json
{
"include": ["src/**/*", "tests/**/*"]
}
19
json
{ "include": ["src/**/*", "tests/**/*"] }
A series of entries which re-map imports to lookup locations relative to the . There is a larger coverage of
19 in .json
{
"include": ["src/**/*", "tests/**/*"]
}
19 lets you declare how TypeScript should resolve an import in yourjson
{
"include": ["src/**/*", "tests/**/*"]
}
23/json
{
"include": ["src/**/*", "tests/**/*"]
}
98s.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
8json
{
"include": ["src/**/*", "tests/**/*"]
}
This would allow you to be able to write
25, and get all of the correct typing locally.json
{
"include": ["src/**/*", "tests/**/*"]
}
9json
{
"include": ["src/**/*", "tests/**/*"]
}
In this case, you can tell the TypeScript file resolver to support a number of custom prefixes to find code. This pattern can be used to avoid long relative paths within your codebase.
Menyelesaikan Module JSON - json
{
"include": ["src/**/*", "tests/**/*"]
}
26
json
{ "include": ["src/**/*", "tests/**/*"] }
Memperbolehkan mengimpor modul dengan ekstensi ‘.json’ merupakan praktik umum pada proyek node. Ini termasuk membuat jenis untuk
98 berdasarkan bentuk JSON statis.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
TypeScript tidak mendukung penyelesaian berkas JSON secara bawaan:
0
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Mengaktifkan opsi memungkinkan impor JSON, dan memvalidasi jenis dalam berkas JSON tersebut.
1
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Root Dir - json
{
"include": ["src/**/*", "tests/**/*"]
}
28
json
{ "include": ["src/**/*", "tests/**/*"] }
Bawaan: Jalur umum terpanjang dari semua berkas masukan non-deklarasi. Jika
29 disetel, bawaannya adalah direktori yang berisi berkasjson
{
"include": ["src/**/*", "tests/**/*"]
}
72.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Ketika TypeScript mengkompilasi berkas, ia mempertahankan struktur direktori yang sama pada direktori keluaran seperti struktur di direktori masukan.
Misalnya, Anda memiliki beberapa berkas masukan:
2
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Kesimpulan untuk
28 adalah jalur umum terpanjang dari semua berkas masukan non-deklarasi, yang dalam hal ini adalahjson
{
"include": ["src/**/*", "tests/**/*"]
}
32.json
{
"include": ["src/**/*", "tests/**/*"]
}
Jika nilai
03 anda adalah
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
34, maka TypeScript akan membuat struktur direktori seperti ini:json
{
"include": ["src/**/*", "tests/**/*"]
}
3
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Namun, anda mungkin mengharapkan
35 menjadi bagian dari struktur direktori keluaran. Dengan menyeteljson
{
"include": ["src/**/*", "tests/**/*"]
}
36 padajson
{
"include": ["src/**/*", "tests/**/*"]
}
72, TypeScript akan menghasilkan struktur direktori seperti ini:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
4
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Yang terpenting,
28 tidak memengaruhi berkas mana yang menjadi bagian dari kompilasi.json
{
"include": ["src/**/*", "tests/**/*"]
}
28 tidak memiliki hubungan dengan pengaturanjson
{
"include": ["src/**/*", "tests/**/*"]
}
61,
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
64, atau
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
60 pada
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
72
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Perhatikan bahwa TypeScript tidak akan pernah menulis berkas keluaran [file output] ke direktori di luar dari
03, dan tidak akan pernah melewatkan pengeluaran berkas. Karena alasan ini,
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
28 mengharuskan semua berkas yang perlu dikeluarkan berada dibawah jalurjson
{
"include": ["src/**/*", "tests/**/*"]
}
28.json
{
"include": ["src/**/*", "tests/**/*"]
}
Misalnya, Anda memiliki struktur direktori seperti ini:
5
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Ini akan menimbulkan galat ketika menentukan
28 sebagaijson
{
"include": ["src/**/*", "tests/**/*"]
}
35 danjson
{
"include": ["src/**/*", "tests/**/*"]
}
61 sebagai
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
79 karena ini membuat berkas [
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
51] yang perlu diletakkan di luar darijson
{
"include": ["src/**/*", "tests/**/*"]
}
03 [yaitu
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
53]json
{
"include": ["src/**/*", "tests/**/*"]
}
- Default:
Computed from the list of input files.
- Released:
1.5
Root Dirs - json
{
"include": ["src/**/*", "tests/**/*"]
}
54
json
{ "include": ["src/**/*", "tests/**/*"] }
Dengan menggunakan
54, Anda dapat memberi tahu kompilator bahwa ada banyak direktori “virtual” yang bertindak sebagai salah satu akar [root]. Hal ini memungkinkan kompilator untuk menyelesaikan impor pada modul relatif dalam direktori “virtual”, seolah-olah digabungkan menjadi satu direktori.json
{
"include": ["src/**/*", "tests/**/*"]
}
Sebagai contoh:
6
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
7
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Ini tidak memengaruhi bagaimana Typescript menghasilkan Javascript, ini hanya mengemulasi asumsi bahwa mereka akan mampu melakukan perkerjaan melalui Jalur relatif tersebut saat runtime.
- Default:
Computed from the list of input files.
- Released:
2.0
Type Roots - json
{
"include": ["src/**/*", "tests/**/*"]
}
56
json
{ "include": ["src/**/*", "tests/**/*"] }
By default all visible ”
57” packages are included in your compilation. Packages injson
{
"include": ["src/**/*", "tests/**/*"]
}
58 of any enclosing folder are considered visible. For example, that means packages withinjson
{
"include": ["src/**/*", "tests/**/*"]
}
59,json
{
"include": ["src/**/*", "tests/**/*"]
}
60,json
{
"include": ["src/**/*", "tests/**/*"]
}
61, and so on.json
{
"include": ["src/**/*", "tests/**/*"]
}
If
56 is specified, only packages underjson
{
"include": ["src/**/*", "tests/**/*"]
}
56 will be included. For example:json
{
"include": ["src/**/*", "tests/**/*"]
}
8
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
This config file will include all packages under
64 andjson
{
"include": ["src/**/*", "tests/**/*"]
}
65, and no packages fromjson
{
"include": ["src/**/*", "tests/**/*"]
}
66. All paths are relative to thejson
{
"include": ["src/**/*", "tests/**/*"]
}
72.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
Types - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
99
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Secara default, semua visible package ”
57” diikutsertakan dalam kompilasi Anda. Package dalamjson
{
"include": ["src/**/*", "tests/**/*"]
}
58 yang terletak dalam folder lain dianggap sebagai visible. Sebagai contoh, package yang berada dijson
{
"include": ["src/**/*", "tests/**/*"]
}
59,json
{
"include": ["src/**/*", "tests/**/*"]
}
60,json
{
"include": ["src/**/*", "tests/**/*"]
}
61, dan seterusnya dianggap sebagai visible.json
{
"include": ["src/**/*", "tests/**/*"]
}
Jika
99 telah ditentukan, hanya package yang didaftarkan yang akan disertakan pada lingkup global, misalnya:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
9
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Berkas
72 ini hanya akan menyertakan
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
77,json
{
"include": ["src/**/*", "tests/**/*"]
}
78 danjson
{
"include": ["src/**/*", "tests/**/*"]
}
79. Package lainnya di bawah direktorijson
{
"include": ["src/**/*", "tests/**/*"]
}
80 tidak akan diikutsertakan.json
{
"include": ["src/**/*", "tests/**/*"]
}
Apa dampaknya?
Opsi ini tidak memengaruhi bagaimana
81 diikutsertakan dalam kode aplikasi Anda, Sebagai contoh, apabila Anda memilikijson
{
"include": ["src/**/*", "tests/**/*"]
}
82 seperti di pada contoh di atas dan kode seperti berikut:json
{
"include": ["src/**/*", "tests/**/*"]
}
0ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Import
83 akan sepenuhnya diketik.json
{
"include": ["src/**/*", "tests/**/*"]
}
Ketika Anda memiliki opsi ini pada pengaturan tanpa menyertakan sebuah modul dalam array
99, maka:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- globals tidak akan ditambahkan ke dalam proyek Anda [contoh:
85 pada node ataujson
{
"include": ["src/**/*", "tests/**/*"]
}
86 pada Jest]json
{
"include": ["src/**/*", "tests/**/*"]
}
- Ekspor tidak akan muncul sebagai rekomendasi auto-import
Pengaturan pada fitur ini hanya tentang menentukan
99 yang ingin Anda sertakan, sedangkan mendukung apabila Anda hanya menginginkan folder-folder tertentu saja.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
Emit
Declaration - json
{
"include": ["src/**/*", "tests/**/*"]
}
90
json
{ "include": ["src/**/*", "tests/**/*"] }
Buat berkas
84 untuk setiap berkas TypeScript atau JavaScript di dalam proyek Anda. Berkas
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
84 ini adalah berkas definisi tipe yang menjelaskan API eksternal modul Anda. Dengan berkas
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
84, alat seperti TypeScript dapat menyediakan tipe yang masuk akal di dalam sumber kode tanpa definisi tipe data.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Jika
90 disetel kejson
{
"include": ["src/**/*", "tests/**/*"]
}
10, jalankan compiler dengan kode TypeScript:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
1ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Akan menghasilkan berkas
96 seperti ini:json
{
"include": ["src/**/*", "tests/**/*"]
}
2ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Dengan
97 yang sesuai:json
{
"include": ["src/**/*", "tests/**/*"]
}
3ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Saat bekerja dengan berkas
84 untuk file JavaScript, Anda mungkin ingin menggunakan atau menggunakan untuk memastikan bahwa berkas JavaScript tidak ditimpa.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Default:
10 if ,,{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
1.0
Declaration Dir - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
04
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Menawarkan cara untuk mengonfigurasi direktori root tempat berkas deklarasi dihasilkan.
4ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
dengan
72;
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
5ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Akan menempatkan d.ts untuk
08 di direktori
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
99:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
6ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
- Related:
- Released:
2.0
_Declaration Map_ - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
11
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Menghasilkan peta sumber untuk berkas
84 yang mengarahkan kembali ke berkas sumber
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
82 asli. Ini akan memungkinkan editor seperti VS Code untuk pergi ke file
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
82 asli saat menggunakan fitur seperti Go to Definition.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Anda harus mempertimbangkan untuk mengaktifkan ini jika Anda menggunakan referensi proyek.
- Released:
2.9
Iterasi tingkat bawah - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
15
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Downleveling adalah istilah TypeScript untuk mentranspilasi ke versi JavaScript yang lebih lama. Saran ini untuk mengaktifkan dukungan implementasi yang lebih akurat tentang bagaimana JavaScript modern melakukan iterasi melalui konsep baru di runtime JavaScript yang lebih lama.
ECMAScript 6 menambahkan beberapa iterasi primitif baru: loop
16 [
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
17], Array spread [
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
18], penyebaran argumen [
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
19], dan
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
20.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
21 memungkinkan iterasi primitif ini digunakan secara lebih akurat dalam lingkungan ES5 jika ada implementasi
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
20.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Contoh: Efek pada .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
16
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Tanpa
15 aktif, loop
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
16 pada objek apa pun diturunkan levelnya menjadi loop
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
26 tradisional:
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
7ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Hal ini sering kali diharapkan orang, tetapi tidak 100% sesuai dengan perilaku ECMAScript 6. String tertentu, seperti emoji [😜], memiliki
27 2 [atau bahkan lebih!], Tetapi harus diiterasi sebagai 1 unit dalam loop
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
28. Lihat postingan blog oleh Jonathan New untuk penjelasan yang lebih lengkap.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Jika
15 diaktifkan, TypeScript akan menggunakan fungsi bantuan yang memeriksa implementasi
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
20 [baik native maupun polyfill]. Jika implementasi ini hilang, Anda akan kembali ke iterasi berbasis indeks.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
8ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Catatan: memungkinkan
15 tidak meningkatkan kepatuhan jika
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
20 tidak ada saat runtime.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Contoh: Efek pada Array Spreads
ini adalah array spread:
9ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Berdasarkan uraian tersebut, sepertinya mudah untuk menurunkan ke ES5:
0ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Namun, ini sangat berbeda dalam kasus tertentu yang jarang terjadi. Misalnya, jika sebuah array memiliki “lubang” di dalamnya, indeks yang hilang akan membuat properti own jika disebarkan, tetapi tidak akan jika dibuat menggunakan
33:
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
1ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Seperti halnya dengan
16,
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
15 akan menggunakan
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
20 [jika ada] untuk meniru perilaku ES 6 dengan lebih akurat.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
- Related:
- Released:
2.3
_Emit BOM_ - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
38
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Mengontrol apakah TypeScript akan menghasilkan tanda urutan byte [byte order mark - BOM] saat menulis berkas output. Beberapa lingkungan runtime memerlukan BOM untuk menafsirkan berkas JavaScript dengan benar; yang lain mengharuskan itu tidak ada. Nilai bawaan dari
62 umumnya paling baik kecuali Anda memiliki alasan untuk mengubahnya.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Menghasilkan Deklarasi Saja - json
{
"include": ["src/**/*", "tests/**/*"]
}
99
json
{ "include": ["src/**/*", "tests/**/*"] }
Hanya menghasilkan berkas
84; jangan mengirimkan berkas
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
85.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Pengaturan ini berguna dalam dua kasus:
- Anda menggunakan transpiler selain TypeScript untuk membuat JavaScript Anda.
- Anda menggunakan TypeScript hanya untuk menghasilkan berkas
43 untuk konsumen Anda.. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
- Related:
- Released:
2.8
Import Helpers - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
37
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Untuk operasi penurunan tingkat tertentu, TypeScript menggunakan beberapa kode penunjang untuk operasi seperti memperluas kelas, himpunan[spread] susunan atau objek, dan menyambungkan operasi. Secara umum, penunjang ini dimasukkan ke dalam berkas yang menggunakannya. Ini dapat mengakibatkan duplikasi kode jika penunjang yang sama digunakan di banyak berkas yang berbeda.
Jika
37 kode ini aktif, fungsi penunjang ini diimpor dari tslib modul. Anda perlu memastikan bahwa berkas
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
47 modul dapat diimpor saat dijalankan. Ini hanya mempengaruhi modul, berkas kode tidak akan mencoba mengimpor modul.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Misalnya, dengan TypeScript:
2ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Memasang dan
37 masih salah:
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
3ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Lalu aktifkan keduanya dan
37:
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
4ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Anda bisa menggunakan saat menyediakan implementasi untuk fungsi-fungsi ini.
- Related:
Impor Tidak Digunakan Sebagai Nilai - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
55
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Kode ini mengontrol cara kerja
98, ada 3 opsi berbeda:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
57: Perilaku umum untuk menghapus pernyataan. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
98 yang hanya merupakan acuan dari kata.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
59: Mempertahankan semua pernyataan. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
98 yang nilai atau katanya tidak pernah digunakan. Hal ini dapat menyebabkan impor/efek samping yang tetap dipertahankan.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
61: Ini mempertahankan semua impor [sama seperti pilihan], tetapi akan mengalami galat jika impor nilai hanya digunakan sebagai tipe data. Ini mungkin berguna jika Anda ingin memastikan tidak ada nilai yang diimpor secara tidak sengaja, tetapi tetap membuat impor dengan jelas.. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Kode ini berfungsi karena Anda dapat menggunakan
62 secara jelas dengan pernyataan
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
98 yang tidak boleh dimasukkan ke JavaScript.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Default:
57. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
- Allowed:
57. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
59. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
61. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
- Released:
3.8
Peta Sumber Sebaris - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
68
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Jika disetel, ketika menulis berkas
69 untuk menyediakan peta sumber, TypeScript akan menyematkan konten peta sumber di berkas
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
85. Meskipun ini menghasilkan berkas JS yang lebih besar, tapi dapat memudahkan dalam beberapa tahap. Misalnya anda mungkin ingin mencoba berkas JS pada server web, tapi tidak mengizinkan berkas
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
71 untuk ditampilkan.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Saling terpisah dengan .
Misalnya, dengan TypeScript:
5ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Di ubah menjadi JavaScript:
6ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Kemudian aktifkan pembuatannya dengan
68, ada komentar di bagian bawah berkas yang menyertakan peta sumber untuk berkas tersebut.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
7ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
- Released:
1.5
Sumber Sebaris - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
74
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Jika dilihat, TypeScript akan menyertakan konten asli dari berkas
82 sebagai string yang disematkan di peta sumber. Ini sering kali berguna dalam kasus yang sama seperti
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
68.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Membutuhkan
72 atau
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
68 untuk disetel.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Misalnya, dengan TypeScript:
8ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Di ubah menjadi JavaScript:
6ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Kemudian dengan
74 dan
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
68 diaktifkan, ada komentar di bagian bawah berkas yang menyertakan peta sumber untuk berkas tersebut. Perhatikan bahwa ada yang berbeda di akhir [
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
68] [# inlineSourceMap] karena peta sumber sekarang berisi kode sumber asli.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
0ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
- Released:
1.5
Map Root - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
82
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Specify the location where debugger should locate map files instead of generated locations. This string is treated verbatim inside the source-map, for example:
1ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
Would declare that
96 will have sourcemaps atjson
{
"include": ["src/**/*", "tests/**/*"]
}
84.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
New Line - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
85
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Specify the end of line sequence to be used when emitting files: ‘CRLF’ [dos] or ‘LF’ [unix].
- Default:
Platform specific.
- Allowed:
86. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
87. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
- Released:
1.5
No Emit - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
88
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Do not emit compiler output files like JavaScript source code, source-maps or declarations.
This makes room for another tool like Babel, or swc to handle converting the TypeScript file to a file which can run inside a JavaScript environment.
You can then use TypeScript as a tool for providing editor integration, and as a source code type-checker.
No Emit Helpers - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
52
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Instead of importing helpers with , you can provide implementations in the global scope for the helpers you use and completely turn off emitting of helper functions.
For example, using this
91 function in ES5 requires a
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
92-like function and
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
93-like function to run:
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
2ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
Which creates quite a lot of JavaScript:
3ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
Which can be switched out with your own globals via this flag:
4ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
- Related:
- Released:
1.5
No Emit On Error - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
95
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Do not emit compiler output files like JavaScript source code, source-maps or declarations if any errors were reported.
This defaults to
62, making it easier to work with TypeScript in a watch-like environment where you may want to see results of changes to your code in another environment before making sure all errors are resolved.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Released:
1.4
Out Dir - {
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
03
{ "extends": "./configs/base", "files": ["main.ts", "supplemental.ts"] }
Jika ditentukan, berkas-berkas
85 [maupun
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
84,
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
69, dsb.] akan disertakan ke dalam direktori ini. Struktur direktori dari sumber awal berkas-berkas juga dipertahankan; lihat jika akar yang di perhitungkan bukan yang anda inginkan.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Jika tidak ditentukan, berkas-berkas
85 akan disertakan di direktori yang sama dengan berkas-berkas
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
82 dari mana mereka di hasilkan:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
5ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
Dengan suatu
72 seperti ini:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
6ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
Menjalankan
04 dengan pengaturan ini dapat memindahkan berkas-berkas ke direktorits
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
34:json
{
"include": ["src/**/*", "tests/**/*"]
}
7ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
- Related:
Out File - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
07
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Jika ditentukan, semua berkas global [non-module] akan digabung menjadi satu berkas keluaran tertentu.
Jika
38 adalah
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
75 atau
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
73, semua berkas modul juga akan digabungkan menjadi berkas ini setelah semua konten global.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
Catatan:
07 tidak dapat digunakan kecualits
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
38 adalah
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
64,
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
45, atau
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
44. Opsi ini tidak bisa digunakan untuk membundel modul CommonJS atau ES6.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
- Related:
- Released:
1.0
Preserve Const Enums - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
19
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Do not erase
20 declarations in generated code.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
20s provide a way to reduce the overall memory footprint of your application at runtime by emitting the enum value instead of a reference.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
For example with this TypeScript:
8ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
The default
20 behavior is to convert anyts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
23 to the corresponding number literal, and to remove a reference to the enum from the JavaScript completely.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
9ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
With
19 set tots
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
10, the
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
26 exists at runtime and the numbers are still emitted.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
0ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
This essentially makes such
27 a source-code feature only, with no runtime traces.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
- Default:
10 if ,,{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
preserveValueImports - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
31
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
There are some cases where TypeScript can’t detect that you’re using an import. For example, take the following code:
1ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
or code using ‘Compiles to HTML’ languages like Svelte or Vue.
When combined with : imported types must be marked as type-only because compilers that process single files at a time have no way of knowing whether imports are values that appear unused, or a type that must be removed in order to avoid a runtime crash.
For example, in the following code
33 is a function andts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
34 is a type withts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
29 andts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
31 are enabled:ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
2ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
Which can be fixed by prefixing
34 withts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
20 to mark it as a type-only import:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
3ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
- Related:
- Released:
4.5
Menghapus Komentar - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
41
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Menghapus semua komentar pada berkas Typescript pada saat mengonversi ke berkas Javascript. Pengaturan bawaannya adalah
62
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Sebagai contoh, ini adalah berkas TypeScript yang memiliki komentar JSDoc:
4ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
Ketika
41 disetel kets
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
10:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
5ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
Tanpa menyetel
41 atau menjadikannya sebagaits
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
62:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
6ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
Artinya, komentar anda akan muncul di kode Javascript
Source Map - .
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
72
.
├── scripts ⨯
│ ├── lint.ts ⨯
│ ├── update_deps.ts ⨯
│ └── utils.ts ⨯
├── src ✓
│ ├── client ✓
│ │ ├── index.ts ✓
│ │ └── utils.ts ✓
│ ├── server ✓
│ │ └── index.ts ✓
├── tests ✓
│ ├── app.test.ts ✓
│ ├── utils.ts ✓
│ └── tests.d.ts ✓
├── package.json
├── tsconfig.json
└── yarn.lock
Enables the generation of sourcemap files. These files allow debuggers and other tools to display the original TypeScript source code when actually working with the emitted JavaScript files. Source map files are emitted as
69 [or
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
49] files next to the correspondingts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
85 output file.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
The
85 files will in turn contain a sourcemap comment to indicate where the files are to external tools, for example:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
7ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
Compiling with
72 set to
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
10 creates the following JavaScript file:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
8ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
And this also generates this json map:
9ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
Source Root - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
54
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Specify the location where a debugger should locate TypeScript files instead of relative source locations. This string is treated verbatim inside the source-map where you can use a path or a URL:
00
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Would declare that
96 will have a source file atjson
{
"include": ["src/**/*", "tests/**/*"]
}
56.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Strip Internal - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
57
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Do not emit declarations for code that has an
58 annotation in its JSDoc comment. This is an internal compiler option; use at your own risk, because the compiler does not check that the result is valid. If you are searching for a tool to handle additional levels of visibility within yourts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
43 files, look at api-extractor.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
01
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
With the flag set to
62 [default]:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
02
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
With
57 set tots
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
10 the
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
43 emitted will be redacted.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
03
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
The JavaScript output is still the same.
- Internal
JavaScript Support
Allow JS - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
87
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Izinkan berkas JavaScript diimpor ke dalam proyek Anda, bukan hanya berkas
82 dan
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
83. Contoh, berkas JS ini:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
04
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Ketika diimpor ke berkas TypeScript akan menimbulkan galat seperti berikut:
05
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Impor berkas akan baik-baik saja saat
87 diaktifkan:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
06
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Opsi ini dapat digunakan sebagai cara untuk menambahkan berkas TypeScript secara bertahap ke dalam proyek JS dengan mengizinkan berkas
82 dan
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
83 untuk hidup berdampingan dengan berkas JavaScript yang ada.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
1.8
Check JS - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
70
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Bekerja sama dengan
87. Kapan
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
70 diaktifkan kemudian kesalahan dilaporkan dalam berkas JavaScript. Ini termasukts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
75 di bagian atas semua berkas JavaScript yang disertakan dalam proyek Anda.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Misalnya, ini adalah JavaScript yang salah menurut definisi jenis
76 yang disertakan dengan TypeScript:ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
07
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Saat diimpor ke modul TypeScript:
08
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Anda tidak akan mendapatkan kesalahan apapun. Namun, jika Anda mengaktifkan
70 maka Anda akan mendapatkan pesan kesalahan dari berkas JavaScript.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
09
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
2.3
Max Node Module JS Depth - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
80
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
The maximum dependency depth to search under
81 and load JavaScript files.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
This flag is can only be used when is enabled, and is used if you want to have TypeScript infer types for all of the JavaScript inside your
81.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Ideally this should stay at 0 [the default], and
43 files should be used to explicitly define the shape of modules. However, there are cases where you may want to turn this on at the expense of speed and potential accuracy.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Editor Support
Nonaktifkan Batas Ukuran - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
85
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Untuk menghindari kemungkinan masalah pembengkakan memori saat bekerja dengan proyek JavaScript yang sangat besar, ada batas atas jumlah memori yang akan dialokasikan TypeScript. Mengaktifkan saran ini akan menghapus batas.
Plugins - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
86
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
List of language service plugins to run inside the editor.
Language service plugins are a way to provide additional information to a user based on existing TypeScript files. They can enhance existing messages between TypeScript and an editor, or to provide their own error messages.
For example:
- — Adds SQL linting with a template strings SQL builder.
- typescript-styled-plugin — Provides CSS linting inside template strings .
- typescript-eslint-language-service — Provides eslint error messaging and fix-its inside the compiler’s output.
- ts-graphql-plugin — Provides validation and auto-completion inside GraphQL query template strings.
VS Code has the ability for a extension to , and so you may have some running in your editor without needing to define them in your
72.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Interop Constraints
Izinkan Setelan Standar Impor Sintetis - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
88
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Jika disetel ke true
88 memungkinkan Anda untuk menulis impor seperti:ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
10
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
daripada:
11
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Jika modul tidak secara eksplisit menentukan ekspor default.
Misalnya, tanpa
88 disetel ke true:ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
12
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Kode ini menimbulkan galat karena tidak ada objek
91 yang dapat Anda impor. Meski rasanya seperti itu seharusnya. Untuk kenyamanan, transpiler seperti Babel akan secara otomatis membuat setelan standar jika tidak dibuat. Membuat modul terlihat lebih seperti:ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
13
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Opsi ini tidak memengaruhi JavaScript yang dihasilkan oleh TypeScript, ini hanya untuk type checking. Opsi ini membuat perilaku TypeScript sejalan dengan Babel, di mana kode ekstra akan ditambahkan kedalam setelan standar ekspor untuk membuat sebuah modul lebih ergonomis.
- Default:
10 if is{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
75, or and is not{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
76/{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
77 or{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
80,,{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
62 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
1.8
Interop Modul ES - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
95
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Secara bawaan [dengan
95 false atau tidak disetel] TypeScript memperlakukan modul CommonJS/AMD/UMD mirip dengan modul ES6. Dalam melakukan ini, ada dua bagian tertentu yang ternyata merupakan asumsi yang salah:ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Impor namespace seperti
04 bertindak sama sepertits
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
05ts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Impor bawaan seperti
06 berfungsi sama sepertits
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
07ts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Ketidakcocokan ini menyebabkan dua masalah berikut:
Spesifikasi modul ES6 menyatakan bahwa impor namespace [
08] hanya dapat menjadi objek, dengan memiliki TypeScript memperlakukannya sama dengants
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
09 maka TypeScript diizinkan untuk impor diperlakukan sebagai fungsi dan dapat dipanggil. Ini melanggar rekomendasi spesifikasi.ts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Meskipun akurat untuk spesifikasi modul ES6, sebagian besar pustaka dengan modul CommonJS/AMD/UMD tidak seketat implementasi TypeScript.
Mengaktifkan
95 akan memperbaiki kedua masalah ini dalam kode yang ditranspilasi oleh TypeScript. Perubahan pertama perilaku di kompilator, yang kedua diperbaiki oleh dua fungsi pembantu baru yang menyediakan shim untuk memastikan kompatibilitas dalam JavaScript yang dihasilkan:ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
14
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Dengan menonaktifkan
95:ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
15
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Dengan
95 disetel kets
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
10:
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
16
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Catatan: Anda dapat meminimalisir ukuran keluaran dengan mengaktifkan :
17
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Mengaktifkan
95 juga akan mengaktifkan .ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
- Recommended
- Related:
- Released:
2.7
Paksa Jenis Huruf Konsisten Dalam Nama berkas - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
18
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
TypeScript mengikuti aturan sensitifitas huruf besar dari sistem berkas yang menjalankannya. Ini bisa menjadi masalah jika beberapa pengembang bekerja dalam sistem berkas sensitifitas huruf besar dan kecil dan yang lainnya tidak. Jika sebuah berkas mencoba mengimpor
19 dengan menetapkants
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
20, berkas tersebut akan ditemukan dalam sistem berkas yang tidak peka huruf besar/kecil, tetapi tidak pada sistem berkas yang peka huruf besar kecil.ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Ketika opsi ini disetel, TypeScript akan mengeluarkan galat jika program mencoba memasukkan berkas dengan jenis huruf yang berbeda dari jenis huruf pada disk.
- Recommended
Modul Terisolasi [_Isolated Modules_] - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
29
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Meskipun Anda dapat menggunakan TypeScript untuk menghasilkan ke kode JavaScript, penggunaan transpiler lain seperti Babel juga umum untuk dilakukan. Namun, transpiler lain hanya beroperasi di satu berkas pada satu waktu, yang berarti mereka tidak dapat menerapkan transformasi kode yang bergantung pada pemahaman sistem tipe penuh. Pembatasan ini juga berlaku untuk API
22 TypeScript yang digunakan oleh beberapa alat pengembang.ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Batasan ini dapat menyebabkan masalah waktu proses dengan beberapa fitur TypeScript seperti
20s dants
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
24s. Pilihants
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
29 memberi tahu TypeScript untuk memperingatkan Anda jika menulis kode tertentu yang tidak dapat diartikan dengan benar oleh proses transpilasi berkas tunggal.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Itu tidak mengubah kode Anda atau mengubah perilaku proses pemeriksaan dan pengecekan kode TypeScript.
Beberapa contoh kode yang tidak berfungsi saat
29 diaktifkan.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Ekspor Pengenal Non-Nilai
Di TypeScript, Anda dapat mengimpor type dan kemudian mengekspornya:
18
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Karena tidak ada nilai untuk
27,ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
28 yang ditampilkan tidak akan mencoba mengekspornya [ini akan menjadi galat waktu proses di JavaScript]:ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
19
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Transpiler satu berkas tidak tahu apakah
27 menghasilkan nilai atau tidak, jadi itu adalah galat untuk mengekspor nama yang hanya mengacu pada sebuah tipe.ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Non-Module Files
Jika
29 dipilih, semua berkas implementasi harus dalam modules [yang berarti memiliki beberapa bentukts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
98 /
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
28]. galat terjadi jika berkas:ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
20
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Pembatasan ini tidak berlaku untuk berkas
84
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Referensi ke anggota ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
20
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Di TypeScript, saat mereferensikan anggota
20, referensi tersebut diganti dengan nilai sebenarnya di JavaScript yang ditampilkan.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Mengubah TypeScript:
21
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Ini untuk JavaScript:
22
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Tanpa pengetahuan tentang nilai anggota ini, transpiler lain tidak dapat menggantikan referensi ke
36, yang akan menjadi galat dijalankan jika dibiarkan [karena tidak ada objekts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
37 pada waktu proses]. Karena itu, ketikats
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
29 dipilih, akan terjadi galat yang mereferensikan anggotats
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
20 di sekelilingnya.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Preserve Symlinks - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
40
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
This is to reflect the same flag in Node.js; which does not resolve the real path of symlinks.
This flag also exhibits the opposite behavior to Webpack’s
41 option [i.e. setting TypeScript’sts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
40 to true parallels setting Webpack’sts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
41 to false, and vice-versa].ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
With this enabled, references to modules and packages [e.g.
98s and
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
45 directives] are all resolved relative to the location of the symbolic link file, rather than relative to the path that the symbolic link resolves to.ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Backwards Compatibility
Charset - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
46
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
Di TypeScript versi sebelumnya, ini mengontrol pengkodean yang digunakan saat membaca berkas teks dari memori. Saat ini, TypeScript mengasumsikan pengkodean UTF-8, tetapi akan mendeteksi dengan benar UTF-16 [BE dan LE] atau UTF-8 BOMs.
- Deprecated
- Default:
47ts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Keyof Strings Only - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
48
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
This flag changes the
49 type operator to returnts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
50 instead ofts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
51 when applied to a type with a string index signature.ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
This flag is used to help people keep this behavior from .
- Deprecated
- Released:
2.9
No Implicit Use Strict - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
52
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
Anda seharusnya tidak memerlukan ini. Secara bawaan, saat memancarkan sebuah berkas modul kepada sebuah target non-ES6, TypeScript memancarkan sebuah kata pengantar
53 di bagian atas berkas. Ini dapat menonaktifkan setelan kata pengantar itu.ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
23
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
24
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
No Strict Generic Checks - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
54
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
TypeScript will unify type parameters when comparing two generic functions.
25
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
This flag can be used to remove that check.
- Released:
2.4
Out - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
06
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Gunakan sebagai gantinya.
Opsi
06 memproses lokasi akhir dengan dengan cara yang tidak dapat diprediksi atau konsisten. Opsi ini dipertahankan hanya untuk kompatibilitas dengan versi lama dan sudah usang.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
- Deprecated
- Related:
Suppress Excess Property Errors - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
59
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
This disables reporting of excess property errors, such as the one shown in the following example:
26
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
This flag was added to help people migrate to the stricter checking of new object literals in .
We don’t recommend using this flag in a modern codebase, you can suppress one-off cases where you need it using
60.ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Suppress Implicit Any Index Errors - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
61
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
Turning
61 on suppresses reporting the error about implicit anys when indexing into objects, as shown in the following example:ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
27
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Using
61 is quite a drastic approach. It is recommended to use ats
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
64 comment instead:ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
28
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
Language and Environment
Menghasilkan Dekorator Metadata - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
66
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
Mengaktifkan dukungan eksperimental untuk menghasilkan tipe data metadata untuk dekorator yang bekerja dengan modul
67.ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Sebagai contoh, berikut adalah JavaScript
29
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Dengan
66 tidak disetel ke true [bawaan]:ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
30
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Dengan
69 di setel ke true:ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
31
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
Decorators Eksperimental - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
70
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
Menyalakan dukungan eksperimental untuk decorator, yang terdapat pada tahap ke 2 proses standarisasi TC39.
Decorator adalah fitur bahasa pemrograman yang belum diadaptasi secara penuh ke dalam spesifikasi JavaScript. Hal ini berarti bahwa versi implementasi di TypeScript mungkin berbeda dengan implementasi pada JavaScript ketika fitur tersebut telah diputuskan oleh TC39.
Anda dapat mencari tahu lebih lanjut mengenai dukungan decorator di TypeScript pada buku petunjuk.
- Related:
JSX - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
73
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
Mengatur bagaimana konstruksi JSX dihasilkan di dalam file Javascript. Ini hanya akan berpengaruh pada keluaran file JS yang dimulai di file
83.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
75: Menghasilkan filets
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
85 dengan JSX yang diubah seperti pemanggilan{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
77ts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
59: Menghasilkan file. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
79 tanpa mengubah JSXts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
80: Menghasilkan filets
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
79 tanpa mengubah JSXts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
- Allowed:
59. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
75ts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
80ts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
85ts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
86ts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
- Related:
- Released:
2.2
JSX Factory - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
87
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
Mengubah fungsi yang dipanggil pada file
85 ketika melakukan kompilasi elemen-elemen JSX. Perubahan yang paling umum adalah dengan menggunakan
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
92 atauts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
93 dibandingkan penggunaan bawaants
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
94 jika menggunakants
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
95.ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Opsi ini dapat digunakan pada basis per file juga seperti halnya .
- Default:
77ts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
- Allowed:
Any identifier or dotted identifier.
- Related:
jsxFragmentFactory - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
88
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
Menentukan fungsi penghasil fragmen JSX yang akan digunakan ketika menargetkan kompiler react JSX
87 sudah ditentukan, misalnya sepertits
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
03.ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
Opsi ini dapat digunakan pada basis per file juga seperti halnya .
Contoh dengan menggunakan TSConfig berikut ini:
32
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
TSX file berikut:
33
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Akan terlihat seperti:
34
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Default:
05ts
Tryfunction verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
- Related:
- Released:
4.0
jsxImportSource - ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
Try
89
ts
function fn[n: number] { if [n > 5] { return true; } else { return false; } return true; }
Try
Declares the module specifier to be used for importing the
73 andts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
11 factory functions when using asts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
13 orts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
14 which were introduced in TypeScript 4.1.ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
With React 17 the library supports a new form of JSX transformation via a separate import.
For example with this code:
35
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Using this TSConfig:
36
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
The emitted JavaScript from TypeScript is:
37
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
For example if you wanted to use
15, you need a tsconfig like:ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
38
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Which generates code like:
39
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Alternatively, you can use a per-file pragma to set this option, for example:
40
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Would add
16 as an import for thets
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
17 factory.ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
Note: In order for this to work like you would expect, your
18 file must include ants
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
28 orts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
98 so that it is considered a module.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Default:
75ts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
- Related:
- Released:
4.1
Lib - ts
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label. }
}
Try
24
ts
function verifikasiUmur[umur: number] { // Lupa menulis pernyataan 'return' if [umur > 18] { terverifikasi: true; } }
Try
TypeScript includes a default set of type definitions for built-in JS APIs [like
25], as well as type definitions for things found in browser environments [likets
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
26]. TypeScript also includes APIs for newer JS features matching the you specify; for example the definition forts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
28 is available if ists
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
49 or newer.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
You may want to change these for a few reasons:
- Your program doesn’t run in a browser, so you don’t want the
31 type definitionsts
Tryfunction verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
- Your runtime platform provides certain JavaScript API objects [maybe through polyfills], but doesn’t yet support the full syntax of a given ECMAScript version
- You have polyfills or native implementations for some, but not all, of a higher level ECMAScript version
In TypeScript 4.5, lib files can be overriden by npm modules, find out more .
High Level libraries
NameContents68Core definitions for all ES3 and ES5 functionality
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
48Additional APIs available in ES2015 [also known as ES6] -
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
34,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
35,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
36,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
37,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
28,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
39,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
40, etc.ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
49Alias for “ES2015”
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
42Additional APIs available in ES2016 -ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
43, etc.ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
44Alias for “ES2016”ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
45Additional APIs available in ES2017 -ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
46,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
47,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
48,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
49,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
50, typed arrays, etc.ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
51Additional APIs available in ES2018 -ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
91 iterables,
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
53,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
54,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
55, etc.ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
56Additional APIs available in ES2019 -ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
57,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
58,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
59,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
60,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
61, etc.ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
47Additional APIs available in ES2020 -
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
63, etc.ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
64Additional APIs available in ES2021 -ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
65,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
66 etc.ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
46Additional APIs available in ESNext - This changes as the JavaScript specification evolves
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
68DOM definitions -ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
69,ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
26, etc.ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
71APIs available in WebWorker contextsts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
72APIs for the Windows Script Hosting Systemts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
Individual library components
Name73ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
74ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
75ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
76ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
77ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
78ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
79ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
80ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
81ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
82ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
83ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
84ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
85ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
86ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
87ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
88ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
89ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
90ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
91ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
92ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
93ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
94ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
95ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
96ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
97ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
98ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
99ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
00ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
01ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
02ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
03ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
04ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
This list may be out of date, you can see the full list in the TypeScript source code.
- Related:
- Released:
2.0
moduleDetection - ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
06
ts
interface UserDefaults { // The absence of a value represents 'system' colorThemeOverride?: "dark" | "light"; }
There are three choices:
07 [default] - TypeScript will not only look for import and export statements, but it will also check whether thets
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
08 field in ats
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
63 is set to{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
10 when running with :ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
57 or{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
56, and check whether the current file is a JSX file when running under :{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
85.ts
Tryfunction fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
16 - The same behavior as 4.6 and prior, usings import and export statements to determine whether a file is a module.ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
17 - Ensures that every non-declaration file is treated as a module.ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
- Default:
"auto": Treat files with imports, exports, import.meta, jsx [with jsx: react-jsx], or esm format [with module: node16+] as modules.
- Allowed:
18ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
19ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
20ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
- Released:
4.7
No Lib - ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
05
ts
interface UserDefaults { // The absence of a value represents 'system' colorThemeOverride?: "dark" | "light"; }
Disables the automatic inclusion of any library files. If this option is set,
24 is ignored.ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
TypeScript cannot compile anything without a set of interfaces for key primitives like:
23,ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
24,ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
25,ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
26,ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
36,ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
28,ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
29, andts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
30. It is expected that if you usets
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
05 you will be including your own type definitions for these.ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
- Related:
React Namespace - ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
33
ts
interface UserDefaults { // The absence of a value represents 'system' colorThemeOverride?: "dark" | "light"; }
Gunakan sebagai gantinya. Tentukan objek yang dipanggil oleh
35 ketika menargetkants
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
75 pada berkas TSX.ts
Try
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
Unreachable code detected.7027Unreachable code detected.}
- Default:
37ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
Target - {
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
66
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } }
Beberapa browser modern mendukung semua fitur ES6, jadi
49 merupakan pilihan yang baik. Anda dapat memilih untuk menyetel sasaran yang lebih rendah apabila kode Anda diluncurkan untuk lingkungan yang lebih lama, atau sebuah sasaran yang lebih tinggi apabila kode Anda dijamin untuk dapat berjalan di lingkungan yang lebih baru.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
Pengaturan
66 mengubah fitur JS mana yang diturunkan levelnya dan mana yang dibiarkan utuh. Sebagai contoh, sebuah arrow_function
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
41 akan berubah menjadi sebuah ekspresi yang ekuivalen dengants
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
42 apabilats
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
66 merupakan ES5 atau versi yang lebih rendah.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
Mengubah
66 berarti juga mengubah nilai default dari . Anda dapat mengatur
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
66 dan
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
24 sesuai keinginan, tetapi Anda dapat menyetelts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
66 untuk alasan kenyamanan.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
Jika Anda hanya bekerja dengan Node.js, berikut adalah beberapa
66 yang direkomendasikan berdasarkan versi Node:NamaTarget yang didukungNode 8
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
45Node 10ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
51Node 12ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
56ts
Try
function verifikasiUmur[umur: number] {
// Lupa menulis pernyataan 'return'
if [umur > 18] {
terverifikasi: true;
Unused label.7028Unused label.}
}
Ini didasarkan pada database dukungan node.green.
Nilai khusus
46 merujuk pada versi tertinggi yang didukung oleh versi TypeScript Anda. Pengaturan ini harus dilakukan secara hati-hati, karena ini tidak berarti hal yang sama pada versi TypeScript yang berbeda dan dapat membuat peningkatan kurang dapat diprediksi.
{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
- Default:
67{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
- Allowed:
55ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
56ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
76/{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
77{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
59ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
60ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
61ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
62ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
78{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
64ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
79{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
80{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
- Released:
1.0
Use Define For Class Fields - ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
67
ts
interface UserDefaults { // The absence of a value represents 'system' colorThemeOverride?: "dark" | "light"; }
This flag is used as part of migrating to the upcoming standard version of class fields. TypeScript introduced class fields many years before it was ratified in TC39. The latest version of the upcoming specification has a different runtime behavior to TypeScript’s implementation but the same syntax.
This flag switches to the upcoming ECMA runtime behavior.
You can read more about the transition in .
- Default:
10 if is{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
70 or higher, includingts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
46,,{
"extends": "./tsconfig",
"compilerOptions": {
"strictNullChecks": false
}
}
62 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Released:
3.7
Compiler Diagnostics
Diagnostics - ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
73
ts
interface UserDefaults { // The absence of a value represents 'system' colorThemeOverride?: "dark" | "light"; }
Digunakan untuk mengeluarkan informasi diagnostik untuk debugging. Perintah ini adalah subset dari yang lebih merupakan hasil yang dilihat pengguna, dan lebih mudah ditafsirkan.
Jika Anda telah diminta oleh kompilator engineer TypeScript untuk memberikan hasil menggunakan tanda ini dalam sebuah kompilasi, di mana tidak ada salahnya menggunakan sebagai gantinya.
- Deprecated
- Related:
explainFiles - ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
77
ts
interface UserDefaults { // The absence of a value represents 'system' colorThemeOverride?: "dark" | "light"; }
Print names of files which TypeScript sees as a part of your project and the reason they are part of the compilation.
For example, with this project of just a single
08 file
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
41
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Using a
72 which has
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
77 set to true:ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
42
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Running TypeScript against this folder would have output like this:
43
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
The output above show:
- The initial lib.d.ts lookup based on , and the chain of
84 files which are referenced{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- The
08 file located via the default pattern of. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
This option is intended for debugging how a file has become a part of your compile.
- Released:
4.2
Diagnosa yang Diperpanjang - ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
74
ts
interface UserDefaults { // The absence of a value represents 'system' colorThemeOverride?: "dark" | "light"; }
Anda dapat menggunakan opsi ini untuk menemukan dimana TypeScript menghabiskan waktunya selama proses kompilasi. Peralatan ini digunakan untuk memahami karakteristik peforma basis kode Anda secara keseluruhan.
Anda dapat mempelajari lebih lanjut bagaimana mengukur dan memahami hasil keluaran pada bagian wiki peforma.
- Related:
Hasilkan Profil CPU - ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
87
ts
interface UserDefaults { // The absence of a value represents 'system' colorThemeOverride?: "dark" | "light"; }
Opsi ini memberi Anda kesempatan untuk meminta TypeScript mengeluarkan profil CPU v8 selama penyusun dijalankan. Profil CPU dapat memberikan wawasan tentang mengapa proyek Anda bisa lambat.
Opsi ini hanya dapat digunakan dari CLI melalui:
88.ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
44
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Berkas ini dapat dibuka di peramban berbasis chromium seperti Chrome atau Edge Developer di bagian Riwayat CPU. Anda dapat mempelajari lebih lanjut tentang memahami kinerja penyusun di Bagian wiki TypeScript tentang kinerja.
- Default:
89ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
- Released:
3.7
List Emitted Files - ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
90
ts
interface UserDefaults { // The absence of a value represents 'system' colorThemeOverride?: "dark" | "light"; }
Print names of generated files part of the compilation to the terminal.
This flag is useful in two cases:
- You want to transpile TypeScript as a part of a build chain in the terminal where the filenames are processed in the next command.
- You are not sure that TypeScript has included a file you expected, as a part of debugging the .
For example:
4ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
With:
46
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Would echo paths like:
47
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Normally, TypeScript would return silently on success.
List Files - ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
91
ts
interface UserDefaults { // The absence of a value represents 'system' colorThemeOverride?: "dark" | "light"; }
Print names of files part of the compilation. This is useful when you are not sure that TypeScript has included a file you expected.
For example:
4ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
With:
49
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Would echo paths like:
50
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Note if using TypeScript 4.2, prefer which offers an explanation of why a file was added too.
- Related:
Trace Resolution - ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
94
ts
interface UserDefaults { // The absence of a value represents 'system' colorThemeOverride?: "dark" | "light"; }
When you are trying to debug why a module isn’t being included. You can set
94 tots
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
10 to have TypeScript print information about its resolution process for each processed file.
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
You can read more about this in .
- Released:
2.0
Projects
Composite - json
{
"include": ["src/**/*", "tests/**/*"]
}
29
json
{ "include": ["src/**/*", "tests/**/*"] }
Opsi
29 memberlakukan batasan tertentu yang memungkinkan untuk membangun [termasuk TypeScript sendiri, di bawah modejson
{
"include": ["src/**/*", "tests/**/*"]
}
99] untuk menentukan dengan cepat apakah proyek telah dibangun.ts
interface UserDefaults {
// The absence of a value represents 'system'
colorThemeOverride?: "dark" | "light";
}
Saat pengaturan ini aktif:
Setelan
28, jika tidak disetel secara eksplisit, lokasi penyimpanan akan berisi berkasjson
{
"include": ["src/**/*", "tests/**/*"]
}
72.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Semua berkas implementasi harus cocok dengan sebuah
61 contoh atau terdaftar dalam aturan{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
60. Jika batasan ini dilanggar,{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
04 akan memberi tahu Anda berkas mana yang tidak ditentukan.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
90 defaults kejson
{
"include": ["src/**/*", "tests/**/*"]
}
10{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
Anda dapat menemukan dokumentasi tentang proyek TypeScript di the handbook.
- Related:
- Released:
3.0
disableReferencedProjectLoad - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
009
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Dalam program TypeScript multi-proyek, TypeScript akan memuat semua proyek yang tersedia ke dalam memori untuk memberikan hasil yang akurat untuk tanggapan editor yang memerlukan grafik pengetahuan lengkap seperti ‘Temukan Semua Referensi’.
Jika proyek Anda besar, Anda dapat menggunakan saran
009 untuk menonaktifkan pemuatan otomatis semua proyek. Sebaliknya, proyek dimuat secara dinamis saat Anda membuka file melalui editor Anda.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Released:
4.0
Nonaktifkan Pencarian Solusi - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
011
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Saat bekerja dengan proyek TypeScript komposit, opsi ini menyediakan cara untuk menyatakan bahwa Anda tidak ingin proyek disertakan saat menggunakan fitur seperti find all reference atau jump to definition di editor.
Saran ini untuk sesuatu yang dapat Anda gunakan untuk meningkatkan daya tanggap dalam proyek komposit besar.
- Released:
3.8
Nonaktifkan Pengalihan Referensi Proyek Sumber - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
012
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Saat bekerja dengan proyek TypeScript komposit, opsi ini menyediakan cara untuk menuju perilaku di mana berkas d.ts digunakan sebagai batas antar modul. Di 3.7, sumber kebenaran sekarang adalah berkas TypeScript Anda.
- Released:
3.7
Incremental - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
007
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Memberi tahu TypeScript untuk menyimpan informasi tentang grafik proyek dari kompilasi terakhir ke berkas yang disimpan di penyimpanan. Ini membuat serangkaian berkas
014 di folder yang sama dengan keluaran kompilasi Anda. Mereka tidak menggunakan JavaScript saat runtime dan dapat dihapus dengan aman. Anda dapat membaca lebih lanjut di .
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Anda dapat mengontrol nama folder dengan menggunakan pilihan .
- Default:
10 if ,,{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
62 otherwise.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
3.4
TS Build Info File - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
008
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
This setting lets you specify a file for storing incremental compilation information as a part of composite projects which enables faster building of larger TypeScript codebases. You can read more about composite projects in the handbook.
This option offers a way to configure the place where TypeScript keeps track of the files it stores on the disk to indicate a project’s build state — by default, they are in the same folder as your emitted JavaScript.
- Default:
014{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Related:
- Released:
3.4
Output Formatting
No Error Truncation - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
025
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Do not truncate error messages.
With
62, the default.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
51
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
With
10
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
52
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Preserve Watch Output - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
028
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Whether to keep outdated console output in watch mode instead of clearing the screen every time a change happened.
- Internal
Pretty - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
029
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Stylize errors and messages using color and context, this is on by default — offers you a chance to have less terse, single colored messages from the compiler.
- Default:
10{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
Completeness
Melewati pemeriksaan pustaka bawaan - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
031
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Gunakan [
032][# skipLibCheck] sebagai gantinya. Lewati pemeriksaan jenis file deklarasi pustaka bawaan.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Melewati pengecekan pustaka - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
033
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Melewati pemeriksaan jenis berkas deklarasi.
Ini dapat menghemat waktu selama kompilasi dengan mengorbankan akurasi dari sistem type. Misalnya, dua pustaka bisa mendefinisikan dua salinan dari
20 [tipe] yang sama dengan cara yang tidak konsisten. Dibandingkan melakukan pengecekan menyeluruh pada semua berkas
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
}
43, TypeScript akan mengecek tipe data dari kode yang Anda acu secara spesifik di dalam kode sumber aplikasi.
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
Kasus umum dimana Anda mungkin berpikir untuk menggunakan
033 adalah ketika ada dua salinan pustaka di
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
81 Anda. Dalam kasus ini, Anda harus mempertimbangkan untuk menggunakan fitur seperti yarn’s resolutions untuk memastikan hanya ada satu salinan dependency di root Anda atau menyelidiki bagaimana cara memastikan hanya ada satu resolusi dependency untuk memperbaiki masalah tanpa ada alat tambahan.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
- Recommended
- Released:
2.0
Baris Perintah
Opsi Pengawasan
TypeScript 3.8 dilengkapi dengan strategi baru untuk mengawasi direktori, yang krusial menentukan perubahan secara efisien terhadap
81.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Pada sistem operasi seperti Linux, TypeScript memasang direktori pengawas [daripada pengawas berkas] pada
81 dan banyak direktori di dalamnya untuk mendeteksi perubahan pada dependensi. Hal ini dikarenakan banyaknya pengawas berkas sering melebihi berkas-berkas yang terdapat padats
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
81, sedangkan ada lebih sedikit direktori untuk diawasi.ts
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
Karena setiap proyek mungkin bekerja dengan strategi yang berbeda, dan pendekatan baru ini mungkin tidak bekerja dengan baik dengan alur kerja anda, TypeScript 3.8 memperkenalkan opsi
041 yang memungkinkan pengguna untuk memberitahu kompiler/layanan bahasa strategi pengawasan yang mana yang harus digunakan untuk mengawasi berkas dan direktori.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Menganggap Perubahan Hanya Mempengaruhi Dependensi Langsung - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
042
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Ketika opsi ini diaktifkan, TypeScript akan menghindari pemeriksaan ulang/membangun kembali semua berkas yang benar-benar mungkin terpengaruh dan hanya memeriksa ulang/membangun kembali berkas yang telah berubah serta berkas yang langsung mengimpornya.
Ini dapat dianggap sebagai implementasi ‘fast & loose’ dari algoritma pengawas, yang mana bisa secara drastis dapat mengurangi waktu rebuild dengan sesekali harus menjalankan build lengkap untuk mendapatkan semua pesan penyusun kesalahan.
- Released:
3.8
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } } Strategi bagaimana setiap berkas diamati. { "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } } { "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } } { "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } } { "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } } { "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } } watchFile -
043
044: Memeriksa setiap berkas apakah terjadi perubahan pada interval waktu tertentu.
045: Memeriksa setiap berkas apakah terjadi perubahan, tetapi menggunakan metode heuristik untuk memeriksa tipe berkas tertentu yang jarang berubah daripada yang lain.
046: Menggunakan antrian dinamis dimana berkas yang jarang diubah akan jarang diperiksa.
047 [the default]: Berusaha menggunakan even asli sistem operasi/berkas sistem untuk memeriksa perubahan berkas.
048: Berusaha menggunakan event asli sistem operasi/berkas sistem untuk memeriksa perubahan berkas pada direktori parent dari berkas tersebut.
- Allowed:
049{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
050{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
051{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
052{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
053{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
054{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Released:
3.8
watchDirectory - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
055
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Strategi untuk bagaimana seluruh direktori diperhatikan dalam sistem yang tidak memiliki fungsi pengawasan berkas secara rekursif.
044: Memeriksa setiap direktori untuk memantau perubahan beberapa kali dalam satu detik secara periodik pada interval yang telah ditentukan.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
046: Menggunakan sebuah queue dinamis dimana direktori-direktori yang jarang mengalami modifikasi akan lebih jarang diperiksa.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
047 [the default]: Mencoba menggunakan sistem operasi / kejadian asli dari sistem berkas untuk perubahan direktori.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Allowed:
053{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
049{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
051{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
052{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Released:
3.8
fallbackPolling - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
063
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Saat menggunakan peristiwa sistem berkas, opsi ini menetapkan strategi polling yang akan digunakan saat sistem kehabisan pengamat berkas asli dan / atau tidak mendukung pengamat berkas asli.
044: Periksa setiap berkas apakah ada perubahan beberapa kali dalam satu detik pada interval tetap.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
045: Periksa setiap berkas apakah ada perubahan beberapa kali dalam satu detik, tetapi gunakan heuristik untuk memeriksa jenis berkas tertentu lebih jarang daripada yang lain.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
046: Gunakan antrian dinamis di mana berkas yang lebih jarang diubah akan lebih jarang diperiksa.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
067: Menonaktifkan pengawas yang ditunda pada direktori. Menonton yang ditunda berguna ketika banyak perubahan berkas mungkin terjadi sekaligus [misal. Perubahan dalam{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
81 dari menjalankants
function fn[n: number] {
if [n > 5] {
return true;
} else {
return false;
}
return true;
}
069], tetapi Anda mungkin ingin menonaktifkannya dengan tanda ini untuk beberapa penyiapan yang kurang umum.{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Allowed:
070{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
071{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
072{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
073{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
- Released:
3.8
synchronousWatchDirectory - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
067
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Synchronously call callbacks and update the state of directory watchers on platforms that don`t support recursive watching natively. Instead of giving a small timeout to allow for potentially multiple edits to occur on a file.
53
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
excludeDirectories - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
075
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
You can use to drastically reduce the number of files which are watched during
077. This can be a useful way to reduce the number of open file which TypeScript tracks on Linux.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
54
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
excludeFiles - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
076
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
You can use
076 to remove a set of specific files from the files which are watched.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
55
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Type Acquisition
Type Acquisition is only important for JavaScript projects. In TypeScript projects you need to include the types in your projects explicitly. However, for JavaScript projects, the TypeScript tooling will download types for your modules in the background and outside of your node_modules folder.
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } } Disables automatic type acquisition in JavaScript projects: { "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } } enable -
080
56
Include - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
61
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
If you have a JavaScript project where TypeScript needs additional guidance to understand global dependencies, or have disabled the built-in inference via .
You can use
61 to specify which types should be used from DefinitelyTyped:
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
57
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
Exclude - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
64
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
Offers a config for disabling the type-acquisition for a certain module in JavaScript projects. This can be useful for projects which include other libraries in testing infrastructure which aren’t needed in the main application.
58
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
disableFilenameBasedTypeAcquisition - {
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
082
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } }
TypeScript’s type acquisition can infer what types should be added based on filenames in a project. This means that having a file like
086 in your project would automatically download the types for JQuery from DefinitelyTyped.
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}