我正在尝试使用 angular2 在电子中制作一个小程序,它运行良好,直到我尝试在数组上使用 find 函数。在那里,我得到了一个错误
Property 'find' does not exist on type 'MyType[]'.
作为新手,看不懂报错,于是稍微搜索了一下,发现electron使用的js引擎能理解ES5
,而不是ES6
.
这就是为什么 sees6-shim
在 angular2 中使用库填充的原因。但是,如果是这样,我不应该得到这个错误,不是吗?
我的 tsconfig.js 文件是这样的:
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/index",
"typings/index.d.ts"
],
"compileOnSave": false,
"buildOnSave": false
}
我也使用 ,webpack
配置如下:
var path = require('path');
var webpack = require('webpack');
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
module.exports = {
devtool: 'source-map',
debug: true,
entry: {
'angular2': [
'rxjs',
'reflect-metadata',
'angular2/core',
'angular2/router',
'angular2/http'
],
'app': './app/app',
'vendor': [
'es6-shim',
'es6-shim/es6-sham'
]
},
output: {
path: __dirname + '/build/',
publicPath: 'build/',
filename: '[name].js',
sourceMapFilename: '[name].js.map',
chunkFilename: '[id].chunk.js'
},
resolve: {
extensions: ['', '.ts', '.js', '.json', '.css', '.html']
},
module: {
loaders: [{
test: /\.ts$/,
loader: 'ts',
exclude: [/node_modules/]
}]
},
plugins: [
new CommonsChunkPlugin({
name: 'angular2',
filename: 'angular2.js',
minChunks: Infinity
}),
new CommonsChunkPlugin({
name: 'common',
filename: 'common.js'
}),
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js')
]
};
我想,我的项目中存在配置错误。但我找不到它。
先感谢您。
更新 1
以下是package.json文件的内容:
{
"name": "videos-for-kids",
"version": "1.0.0",
"description": "",
"main": "index.js",
"author": "Charalampos Chrysikopoulos",
"license": "ISC",
"scripts": {
"build": "webpack --progress --profile --colors --display-error-details --display-cached",
"watch": "webpack --watch --progress --profile --colors --display-error-details --display-cached",
"start": "electron ."
},
"devDependencies": {
"awesome-typescript-loader": "^0.15.10",
"electron-prebuilt": "^1.2.6",
"electron-reload": "^1.0.0",
"ts-loader": "^0.7.2",
"typescript": "^1.8.10",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0",
"typings": "^1.3.1",
"tslint": "^3.7.4",
"ts-helpers": "^1.1.1",
"imports-loader": "^0.6.5",
"json-loader": "^0.5.4"
},
"dependencies": {
"angular2": "2.0.0-beta.17",
"systemjs": "0.19.26",
"es6-shim": "^0.35.1",
"reflect-metadata": "0.1.2",
"rxjs": "^5.0.0-beta.6",
"zone.js": "^0.6.12",
"bootstrap": "^3.3.6"
}
}
更新 2
这也是有错误的类:
import { Injectable } from 'angular2/core';
import { Http, Response } from 'angular2/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs';
import {IVideo} from '../model/IVideo';
@Injectable()
export class VideoService {
private _serviceUrl = 'file://pathTo/app/data/videos.json';
constructor(private _http: Http) { }
public getVideos(): Observable<IVideo[]> {
return this._http.get(this._serviceUrl)
.map((response: Response) => <IVideo[]> response.json())
.catch(this.handleError);
}
private handleError(error: Response) {
return Observable.throw(error.json().error || 'Server error');
}
getVideo(id: number): Observable<IVideo> {
return this.getVideos()
.map((videos: IVideo[]) => videos.find(v => v.id === id));
}
}