type-challenges / type-challenges

Collection of TypeScript type challenges with online judge

Home Page:https://tsch.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

6 - 简单的 Vue 类型

chenjieya opened this issue · comments

// 你的答案

declare function SimpleVue<D,C,M>(options: {
  data: (this: null) => D,
  // computed中的this可以指向data,并且还可以指向计算属性,准确的说是指向计算属性的返回值 this.fullname.firstname
  computed: C & ThisType<D & getComputedReturn<C>>,
  methods: M & ThisType<D & getComputedReturn<C> & M>
}): any

// 获取到计算属性的返回值类型
type getComputedReturn<T> = {
  [key in keyof T]: T[key] extends (...args: any[]) => infer R ? R : never 
}