1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavascriptでVuex.Storeのmoduleを書く際、VS Codeのコードアシストを効かせる

Posted at

概要

Vuex.Storeのmoduleはplain objectで記述する必要があります。
しかしこれだとVSCodeの補完が効かなくて悲しくなってきます。

image.png

Vuex.Storeのコンストラクタだと具合良く補完が効くのですが・・

解決策: JSDocを記述した薄いラッパーをかませる

そこで、こんな感じの薄いfunctionを用意しました。

store_module.js
import {StoreOptions} from 'vuex' // eslint-disable-line

/**
 * @template T
 * @param {StoreOptions<T>} options
 * @returns {StoreOptions<T>}
 */
export default function StoreModule(options) {
  return options
}

これをかますと、いい感じで補完が効くようになります。

image.png

素直にTypeScriptを使ったほうがいいんでしょうけど。。

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?