首次安裝使用typescript報錯

2021-10-24 06:12:27 字數 3885 閱讀 6555

最近想學typescript,用npm命令

npm install -g typescript

安裝後,執行

tsc -v

想檢視版本檢測是否安裝成功,隨後報錯了

看得我一臉懵逼。網上也查不到任何資訊。

沒辦法只好看**。

開啟tsc.js檔案,看到報錯源頭5970行,是這麼一句,

var texttokeyword =

newts.map

(ts.

getentries

(texttokeywordobj)

);

把texttokeywordobj和ts.getentries的返回值分別用console.log輸出後,

得知texttokeywordobj是這麼乙個物件,

entry為乙個陣列:(entry為ts.getentries返回值)

[,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,,,

,,['abstract',12

['any'

,128],

['as'

,126],

['asserts'

,127

['bigint'

,154

['boolean'

,131

['break',80

],['case',81

],['catch',82

],['class',83

],['continue',85

['const',84

],['constructor',[

'debugger',86

['declare'

,133

['default',87

['delete',88

]['do',89

],['else',90

],['enum',91

],['export',92

]['extends',93

['false',94

],['finally',95

['for',96

],['from'

,152],

['function',97

['get'

,134],

['if',98

],['implements',[

'import',99

]['in'

,100],

['infer'

,135][

'instanceof',[

'inte***ce',1

['is'

,136],

['keyof'

,137][

'let'

,118],

['module'

,138

['namespace',1

['never'

,140][

'new'

,102],

['null'

,103],

['number'

,143

['object'

,144

['package'

,119

['private'

,120

['protected',1

['public'

,122

['readonly',14

['require'

,142

['global'

,153

['return'

,104

['set'

,145],

['static'

,123

['string'

,146

['super'

,105][

'switch'

,106

['symbol'

,147

['this'

,107],

['throw'

,108][

'true'

,109],

['try'

,110],

['type'

,148],

['typeof'

,111

['undefined',1

['unique'

,150

['unknown'

,151

['var'

,112],

['void'

,113],

['while'

,114][

'with'

,115],

['yield'

,124][

'async'

,129][

'await'

,130][

'of'

,155

]]

網上搜了下iterator value undefined is not an entry object,查到這麼一篇部落格,es6語法,裡面有這麼一句,

用陣列建立map結構陣列必須為二維陣列,否則會報這個錯iterator value 1 is not an entry object。和上面的錯誤很像。

很明顯上面的那段**也是想用陣列建立乙個map結構,但是引數非法,所以報錯了。陣列中有大量的空成員,導致輸出大量逗號,也使這個陣列不為二維陣列。

為什麼會輸出大量空成員呢,我又看了下ts.getentries函式,

var _entries = object.entries ? object.entries :

function

(obj)

return result;};

function

getentries

(obj)

ts.getentries = getentries;

裡面出問題的一段**是

var result =

array

(keys.length)

;for

(var _i =

0, keys_1 = keys; _i < keys_1.length; _i++

)

他建立了乙個keys.length大小的陣列,然後再往後面新增成員,這導致前面有大量空的成員,最後得到的陣列大小為2*keys.length。

可以這麼改:

var result =

;for

(var _i =

0, keys_1 = keys; _i < keys_1.length; _i++

)return result;

最後執行成功了。

不知道為什麼會遇到這種問題。我用的typescript是4.0.2。node版本是4.6.2。有知道原因的請跟我說下

python中首次安裝使用nltk

1.在cmd命令提示符視窗中輸入 pip install nltk 2.首次輸入python 時,import nltk text welcome readers.i hope you find it interesting.please do reply.需要加空格 from nltk.token...

pycharm安裝和首次使用教程

pycharm是我用過的python編輯器中,比較順手的乙個。而且可以跨平台,在macos和windows下面都可以用,這點比較好。是python現在最好用的編輯器,沒有之一。首先預覽一下 pycharm 在實際應用中的介面 更改了pycharm的預設風格 安裝官網 官網位址 社群版 communi...

Brew for Mac 首次安裝

按照官方 開啟終端輸入如下 上面安裝完成後,繼續等待安裝。如果出現錯誤 rpc failed curl 18 transfer closed with outstanding read data remaining解決方案 是在終端輸入如下命令 git config global http.post...