How to fix error Cannot find name 'object'

2019-07-09 10:38发布

I have insalled ng2-ckeditor using cli :

npm install ng2-ckeditor --save

Then Include CKEditor javascript files in my index file :

<script src="https://cdn.ckeditor.com/4.5.11/full/ckeditor.js"></script>

Then imported module in module file:

import { CKEditorModule } from 'ng2-ckeditor';

in imports "CKEditorModule"

and trying to use in html

It show error:

ERROR in /var/www/html/eventswebsite/frontendapp/node_modules/ng2-ckeditor/lib/ckeditor.component.d.ts (43,26): Cannot find name 'object'.

"ng2-ckeditor/lib/ckeditor.component.d.ts (43,26): Cannot find name 'object'."

its working if i change ckeditorInit(config: object)

To

ckeditorInit(config: any)

in npm module ckeditor component file.

1条回答
对你真心纯属浪费
2楼-- · 2019-07-09 11:19

I am posting this answer for those who are facing this error "Cannot find name 'object'" irrespective of which component they are getting this error in. This is a tsc compiler version related issue. 'object' is keyword in TS2.2.

I am using VS 2017 Community. By default it shipped with tsc 1.5 ie. typescript compiler version 1.5. I tried updating it from Nuget and also installed "typescript for VS 2017" nothing helped, even though my computer had latest version of typescript, but VS typescript version was still 1.5.

Then I searched for Microsoft's latest update of VS 2017, fortunately for me notification of latest release was found on top bar of VS. After installing the latest update I got my typescript version on VS updated to 2.2. This resolved the issue and compilation errors were gone.

As a side note, you can find the version of typescript VS is using under menu "Help\About Microsoft Visual Studio", then on pop up screen scroll down a bit as shown in below image:typescript version in visual studio 2017

查看更多
登录 后发表回答