У меня есть очень простой компонент, подобный этому:
const MyComponent = Vue.extend({
data() {
return {
x: 0,
y: 0
};
}
});
Я хочу получить такой тип данных:
type MyGoal = {
x: number;
y: number;
};
Я пробовал что-то, но не повезло, пожалуйста см. ниже код:
import Vue, { VueConstructor, ComponentOptions } from "vue";
const MyComponent = Vue.extend({
data() {
return {
x: 0,
y: 0
};
}
});
// Unfortunately, my utility is merging everybody together, it is impossible to extract the type anymore
type ExtractInstance<T> = T extends VueConstructor<infer V> // not working
? V
: T extends ComponentOptions<infer V>
? V
: never;
type Extracted = ExtractInstance<typeof MyComponent>;
// => type Extracted = {
// => x: number; // How can I get these guys?
// => y: number; //
// => } & Record<never, any> & Vue
Возможно ли это сделать без извлечения этой функции данных?