4

我一直在研究在tsconfig.json文件中找到的compilerOptionslib屬性的可能值是什麼意思。我的Typescript GitHub頁面上找到對應於那些值相關的d.ts文件,顯然使用ES2017以下ES功能包括:es6和es2017之間tsconfig.json中'lib'屬性的區別?

/// <reference path="lib.es2016.d.ts" /> 
/// <reference path="lib.es2017.object.d.ts" /> 
/// <reference path="lib.es2017.sharedmemory.d.ts" /> 
/// <reference path="lib.es2017.string.d.ts" /> 
/// <reference path="lib.es2015.d.ts" /> 
/// <reference path="lib.es2016.array.include.d.ts" /> 
/// <reference path="lib.es2015.core.d.ts" /> 
/// <reference path="lib.es2015.collection.d.ts" /> 
/// <reference path="lib.es2015.generator.d.ts" /> 
/// <reference path="lib.es2015.iterable.d.ts" /> 
/// <reference path="lib.es2015.promise.d.ts" /> 
/// <reference path="lib.es2015.proxy.d.ts" /> 
/// <reference path="lib.es2015.reflect.d.ts" /> 
/// <reference path="lib.es2015.symbol.d.ts" /> 
/// <reference path="lib.es2015.symbol.wellknown.d.ts" /> 
/// <reference path="lib.es5.d.ts" /> 

但顯然不包括ES6和有它自己的file不引用任何東西。我的問題是,如果有人知道,可以肯定的是,通過使用es2017我涵蓋了所有es6功能(從類型角度來看),還是應該將其單獨包含在lib選項中?

例如,像這樣:

{ 
    ... 
    "compilerOptions": { 
    ... 
    "lib": ["es2017", "dom"] 
    }, 
    ... 
    } 
} 

OR這樣的:

{ 
    ... 
    "compilerOptions": { 
    ... 
    "lib": ["es2017", "es6", "dom"] 
    }, 
    ... 
    } 
} 
+0

'ES6 == ES2015' – Bergi

+0

@Bergi這不是真的根據打字稿的類型。它包括所有ES2015的東西和其他東西。看到我的答案吼叫。 – Vigidis

回答

4

一些挖掘之後,通過對Typescript GitHublib文件夾中我發現,比較,在lib財產使用es6compilerOptions對應的代碼在這些參考文獻中找到:

/// <reference path="lib.es2015.core.d.ts" /> 
/// <reference path="lib.es2015.collection.d.ts" /> 
/// <reference path="lib.es2015.generator.d.ts" /> 
/// <reference path="lib.es2015.iterable.d.ts" /> 
/// <reference path="lib.es2015.promise.d.ts" /> 
/// <reference path="lib.es2015.proxy.d.ts" /> 
/// <reference path="lib.es2015.reflect.d.ts" /> 
/// <reference path="lib.es2015.symbol.d.ts" /> 
/// <reference path="lib.es2015.symbol.wellknown.d.ts" /> 
/// <reference path="lib.es5.d.ts" /> 
/// <reference path="lib.dom.d.ts" /> 
/// <reference path="lib.scripthost.d.ts.d.ts" /> 
/// <reference path="lib.dom.iterable.d.ts" /> 

這麼回答我的問題,正確地覆蓋es6所有內容與es2017的tsconfig.json的部分應該是這樣的:

{ 
    ... 
    "compilerOptions": { 
    ... 
    "lib": ["es2017", "dom", "dom.iterable", "scripthost"] 
    }, 
    ... 
    } 
} 
相關問題