Type Challenges Judge

Pinia

提出詳細

type Computed<C extends Record<string, any>> = { [P in keyof C]: ReturnType<C[P]> } type O = Record<string, unknown> declare function defineStore<S extends O, G extends O, A extends O>(store: { id: string, state: () => S, getters: G & ThisType<Readonly<S & Computed<G>>>, actions: A & ThisType<S & Readonly<G> & A> }): A & S & Computed<G>
提出日時2024-09-16 14:24:00
問題Pinia
ユーザーookkoouu
ステータスWrong Answer
テストケース
import type { Equal, Expect } from '@type-challenges/utils' const store = defineStore({ id: '', state: () => ({ num: 0, str: '', }), getters: { stringifiedNum() { // @ts-expect-error this.num += 1 return this.num.toString() }, parsedNum() { return parseInt(this.stringifiedNum) }, }, actions: { init() { this.reset() this.increment() }, increment(step = 1) { this.num += step }, reset() { this.num = 0 // @ts-expect-error this.parsedNum = 0 return true }, setNum(value: number) { this.num = value }, }, }) // @ts-expect-error store.nopeStateProp // @ts-expect-error store.nopeGetter // @ts-expect-error store.stringifiedNum() store.init() // @ts-expect-error store.init(0) store.increment() store.increment(2) // @ts-expect-error store.setNum() // @ts-expect-error store.setNum('3') store.setNum(3) const r = store.reset() type _tests = [ Expect<Equal<typeof store.num, number>>, Expect<Equal<typeof store.str, string>>, Expect<Equal<typeof store.stringifiedNum, string>>, Expect<Equal<typeof store.parsedNum, number>>, Expect<Equal<typeof r, true>>, ]