LoginSignup
0
0

More than 1 year has passed since last update.

nuxt + typescriptのtransitionのv-onイベントでdatasetを追加した時のエラー

Last updated at Posted at 2021-08-23

コード

  beforeEnter(el: HTMLElement) {
    console.log(parseInt(el.dataset.index, 10))
  }

エラー

(property) HTMLOrSVGElement.dataset: DOMStringMap
Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'

死んだ、、、、

いろいろ調べた挙句、こうしたら解消した

  beforeEnter(el: HTMLElement) {
    console.log(parseInt(el.dataset.index as string, 10))
  }

その後気づいた。

結論

parseIntで数字と型推論されてたので、
エラーが出てたことに。。。

これで行けたやん。。。

  beforeEnter(el: HTMLElement) {
    console.log(Number(el.dataset.index))
  }

時間よおさらば

0
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
0
0