私はangular2で電子の小さなプログラムを作成しようとしています。配列にfind関数を使用しようとするまでうまくいきました。そこに、私は初心者のようにエラーにElectron + Angular2 + es6-shim。配列にfind関数がありません
Property 'find' does not exist on type 'MyType[]'.
を持って、私はエラーを理解することができませんでしたので、私は少しを検索し、私は使い方を電子JSエンジンがES5
なくES6
理解していることが分かりました。
なぜang2のes6-shim
ライブラリでシミングに使用するのですか?しかし、もしそうなら、私はこのエラーを起こすべきではないでしょうか?
マイ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')
]
};
、私のプロジェクトでの設定ミスがあります。しかし、私はそれを見つけることができません。
ありがとうございます。
{
"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"
}
}
ここUPDATE 2
もエラーとクラスである:ここ
UPDATE 1
はpackage.jsonファイルの内容は
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));
}
}
問題はコンパイル時に発生します。私はこのファイルの内容で質問を更新しました。 Typescriptのバージョンは1.8.10、電子は1.2.6です。それらは大丈夫、私は思うべきである。長い答えをありがとう、私は代替のシムを使用しようとします... –
おそらく、私はこの事がどのように正しく動作するのかを正しく理解していません。私はVisual Studioのコードを使用し、 'find'メソッドのコードがあるファイルを開くと、エラーが表示されます(javaのコンパイルエラーのようです)。 typescriptは私が 'es6-schim'を使用している(または私が使いたいと思う)ことをどのように知ることができますか? 'tsconfig.js'ファイルを通してですか?これは、typescriptが使用している唯一の設定(javaの 'classpath'など)ですか? –
@inky TypeScriptは実際にes6-shimに気付かれていません。あなたのwebpackの中のすべてのものも気にしません。 tsconfig.jsonは、.jsファイルを作成するときに使用するいくつかの重要なポイントをTypeScriptトランスペアラに与えます。たとえば、tsconfig.jsonの設定に基づいてCommonJS形式で.jsファイルを作成する方法を知っています。また、その設定に基づいて "require"構文をナビゲートする方法も知っています。 TSが不平を言っているコードのスニペットを含めることは可能ですか?宣言のスニペットですか? (観測:数)関数にgetVideo(ID) –