Languages

TypeScript - error TS2318: Cannot find global type 'Array'

4 points
Asked by:
Kate_C
19800

When I run my TypeScript project, compiler prints following errors:  

error TS2318: Cannot find global type 'Array'.
error TS2318: Cannot find global type 'Boolean'.
error TS2318: Cannot find global type 'CallableFunction'.
error TS2318: Cannot find global type 'Function'.
error TS2318: Cannot find global type 'IArguments'.
error TS2318: Cannot find global type 'NewableFunction'.
error TS2318: Cannot find global type 'Number'.
error TS2318: Cannot find global type 'Object'.
error TS2318: Cannot find global type 'RegExp'.
error TS2318: Cannot find global type 'String'.

tsconfig.json contains:

{
	"version" : "4.0.3",
	"compilerOptions": {
		"strict": true,
		"target": "es5",
		"module": "amd",
		"lib": ["es2015.promise"],
        "jsx": "react",
		"jsxFactory": "renderElement",
		"jsxFragmentFactory": "renderFragment",
		"allowJs": true,
		"removeComments": true,
        "noImplicitAny": true,
        "preserveConstEnums": true,
		"sourceMap": true,
        "outFile": "src/main/webapp/resources/index.js"
	},
	"files": [
		"src/main/webapp/resources/index.tsx"
	],
	"exclude": [
		"../**/*.d.tsx"
	]
}
1 answer
4 points
Answered by:
Kate_C
19800

You need to add type declarations, so add "es5" into your libs.

"lib": ["es2015.promise", "es5"],

your new configuration should look like:

{
	"version" : "4.0.3",
	"compilerOptions": {
		"strict": true,
		"target": "es5",
		"module": "amd",
		"lib": ["es2015.promise", "es5"],
        "jsx": "react",
		"jsxFactory": "renderElement",
		"jsxFragmentFactory": "renderFragment",
		"allowJs": true,
		"removeComments": true,
        "noImplicitAny": true,
        "preserveConstEnums": true,
		"sourceMap": true,
        "outFile": "src/main/webapp/resources/index.js"
	},
	"files": [
		"src/main/webapp/resources/index.tsx"
	],
	"exclude": [
		"../**/*.d.tsx"
	]
}
0 comments Add comment
Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join