如何使用typescript声明angular.js的类型?

时间:2019-01-21 16:03:04

标签: angularjs typescript-typings

我在Angular.js中有一个带有TypeScript的应用程序。

使用TSC命令编译为js时出现一些错误。 我已经设法通过更改tsconfig并传递类型来处理其中的大多数问题。通过在source.ts文件的顶部添加一些引用来进行尝试。

在VSC的根文件夹中进行编译时,我仍然遇到这些错误:

node_modules/@types/angular/jqlite.d.ts:809:5 - error TS2717: Subsequent property declarations must have the same type.  Property 'char' must be of type 'any', but here has type 'string'.

809     char: string;
        ~~~~

node_modules/@types/angular/jqlite.d.ts:812:5 - error TS2717: Subsequent property declarations must have the same type.  Property 'key' must be of type 'any', but here has type 'string'.

812     key: string;
        ~~~

source.ts:21:38 - error TS2304: Cannot find name 'AppService'.

21         constructor(private service: AppService, private P2PListId: string) {
                                        ~~~~~~~~~~

source.ts:22:29 - error TS2304: Cannot find name 'Model'.

22             this.data = new Model.Form();
                               ~~~~~

source.ts:24:40 - error TS2304: Cannot find name 'Model'.

24             this.data.masterData = new Model.MasterData();
                                          ~~~~~

source.ts:25:46 - error TS2503: Cannot find namespace 'Model'.

25             this.data.detailData = new Array<Model.IDetailData>();
                                                ~~~~~

source.ts:68:35 - error TS2503: Cannot find namespace 'Model'.

68             this.service.http.get<Model.IResource>(`${p2p_appScriptsPath}Resources/lang-${lang}.jsonp`)
                                     ~~~~~

source.ts:74:43 - error TS2503: Cannot find namespace 'Model'.

74                     this.service.http.get<Model.IResource>(`${p2p_appScriptsPath}Resources/lang-${this.defaultLang}.jsonp`)
                                             ~~~~~

source.ts:93:45 - error TS2503: Cannot find namespace 'ListItemsDto'.

93                             var listItem = <ListItemsDto.IP2PListItem> data.results[0];
                                               ~~~~~~~~~~~~

source.ts:99:37 - error TS2304: Cannot find name 'Model'.

99                                     Model.GridStatus.gridStatusResources.forEach((item, index) => {
                                       ~~~~~

source.ts:144:30 - error TS2503: Cannot find namespace 'Model'.

144                             <Model.DetailData>{
                                 ~~~~~

source.ts:158:15 - error TS2503: Cannot find namespace 'Model'.

158         data: Model.IForm;
                  ~~~~~

source.ts:159:17 - error TS2503: Cannot find namespace 'Model'.

159         loaded: Model.MyObject;
                    ~~~~~

../typings/kendo-ui/kendo-ui.d.ts:1194:15 - error TS2430: Interface 'DataSourceTransportWithFunctionOperations' incorrectly extends interface 'DataSourceTransport'.
  Types of property 'create' are incompatible.
    Type '(options: DataSourceTransportOptions) => void' has no properties in common with type 'DataSourceTransportCreate'.

1194     interface DataSourceTransportWithFunctionOperations extends DataSourceTransport {
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../typings/kendo-ui/kendo-ui.d.ts:1532:11 - error TS2559: Type 'AgendaView' has no properties in common with type 'SchedulerView'.

1532     class AgendaView implements kendo.ui.SchedulerView {
               ~~~~~~~~~~

我的tsconfig.jscon:

{
        "compilerOptions": {
            "target": "es5",
            "module": "none",
            "sourceMap": true,
        },
     "include": [
                "../typings/**/*.d.ts"
            ], 
         "files": [
                "source.ts"
              ]
    } 

我的package.json

{
  "name": "scripts",
  "version": "1.0.0",
  "description": "",
  "main": "source.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/angular": "^1.6.53"
  },
  "devDependencies": {
    "@types/node": "^10.12.18",
    "typescript": "^3.2.4"
  }
}

0 个答案:

没有答案