LoginSignup
2
0

More than 3 years have passed since last update.

The keyword 'yield' is reserved ってなによ

Last updated at Posted at 2019-09-03

概要

'yield'は予約語です。

Webアプリのフロント開発をしてたら謎のエラーメッセージと遭遇したので、メモ。

開発環境(フロントエンド)

TypeScript
Vue

ソースコード

service = new SampleService();

search(){
  let sample = await this.service.findall();
  console.log(this.sample);
}

もうお気づきでしょうが・・・await文を使用しているのに、searchメソッドにはasyncがついてません。

これが原因です。

yield?

yieldはジェネレータ関数の一時停止や再開を行う構文だそうで、JavaScriptにおける非同期処理に密接に関わっている様子。
asyncつけないとawaitが機能しないことをJavaScriptでは「The keyword 'yield' is reserved.」と言うのか・・・

修正コード

service = new SampleService();

async search(){ // 修正点
  let sample = await this.service.findall();
  console.log(this.sample);
}

参考文献

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0