Shan Khan Shan Khan - 1 month ago 9
TypeScript Question

Cannot find require index of (string) , Object, Date, Json after upgrading to typescript 2

After converting to typescript 2.0 from 1.8 im getting alot of errors.
The errors and typescript code is.

Cannot Find "JSON"

set = JSON.parse(settin);


Property 'indexOf' , concat does not exist on type 'string'

var appSetting : string = this.en.APP_SETTINGS;
var appSummary : string = this.en.APP_SUMMARY;
while (appSetting.indexOf("/") > -1) {
appSetting = appSetting.replace("/", "\\");
}


Cannot find name 'Object'

public async GetSettings(): Promise<Object> {


Cannot find array in Array()

let items: Array<string> = new Array<string>();


Cannot find Date

public lastUpload: Date = null;


There were problems like require and Promise also but solved after adding shim and types

"devDependencies": {
"@types/es6-shim": "^0.31.32",
"typescript": "^2.0.3",
"vscode": "^1.0.0"
},
"dependencies": {
"@types/node": "^6.0.45",
"adm-zip": "^0.4.7",
"fs": "^0.0.2",
"github": "^2.6.0",
"ncp": "^2.0.0",
"node-watch": "0.4.0",
"open": "^0.0.5",
"rimraf": "^2.5.4",
"temp": "^0.8.3"
}


tsconfig.json


{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"noLib": true,
"sourceMap": true
},
"exclude": [
"node_modules"
]
}

Answer

You have this line:

"noLib": true

In your in tsconfig.json, which causes the compiler to

not include the default library file (lib.d.ts)

I haven't actually ever used that, but from what you're describing it seems that if you'll remove this line the errors should get away.

Comments