Created
July 13, 2022 03:50
-
-
Save vezaynk/9fa29c434d234620c7dbcd9d0a811f95 to your computer and use it in GitHub Desktop.
Solution to Simple Vue by Anthony Fu (@antfu) from typescript-challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ToGetter<T> = { | |
[P in keyof T]: T[P] extends (...args: any) => any ? ReturnType<T[P]> : never; | |
} | |
interface VueOptions<D, C, M> { | |
data: () => D; | |
computed: C; | |
methods: M; | |
} | |
declare function SimpleVue< | |
D, C, M, | |
ComputedProperties = ToGetter<C>, | |
BoundThis = D & ComputedProperties & M & { data: () => D} | |
>(options: | |
VueOptions<D, C, M> | |
& | |
ThisType<BoundThis>): any | |
/* _____________ Test Cases _____________ */ | |
import type { Equal, Expect } from '@type-challenges/utils' | |
SimpleVue({ | |
data() { | |
this.firstname | |
this.getRandom() | |
this.data() | |
return { | |
firstname: 'Type', | |
lastname: 'Challenges', | |
amount: 10, | |
} | |
}, | |
computed: { | |
fullname() { | |
return `${this.firstname} ${this.lastname}` | |
}, | |
}, | |
methods: { | |
getRandom() { | |
return Math.random() | |
}, | |
hi() { | |
alert(this.amount) | |
alert(this.fullname.toLowerCase()) | |
alert(this.getRandom()) | |
}, | |
test() { | |
const fullname = this.fullname | |
const cases: [Expect<Equal<typeof fullname, string>>] = [] as any | |
}, | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment