vuepress / vuepress-community

:bulb: Community supported ecosystem for VuePress
https://vuepress-community.netlify.app
MIT License
81 stars 62 forks source link

[Bug Report] vuepress-types #36

Closed Mister-Hope closed 4 years ago

Mister-Hope commented 4 years ago
export interface PluginOptionAPI {
  extendPageData?: (page: Page) => void | Promise<void>
}

should be

export interface PluginOptionAPI {
  extendPageData?: <T = Record<string,any>>(page: Page & Partial<T>) => void | Promise<void>
}

Otherwise we can not extend it. 🙄

meteorlxy commented 4 years ago

Well, I think you should use Module Augmentation to extend the Page type itself

Mister-Hope commented 4 years ago

Well, good idea

Mister-Hope commented 4 years ago

Nope, we are using PageComputed type in other files, and this function use Page. Extending it has no meaning because it's only used in compiling. see here

Mister-Hope commented 4 years ago

That is, I think we should better change it, and write:

declare 'vuepress-types/types/page' {
  interface PageComputed {
    xxx: yyy;
  }
}

instead of remaining it and write:

declare 'vuepress-types/types/page' {
  interface Page {
    xxx: yyy;
  }

  interface PageComputed {
    xxx: yyy;
  }
}
meteorlxy commented 4 years ago

Extending it has no meaning because it's only used in compiling

Sorry didn't catch your point. Typescript is only used in compiling, too.

Mister-Hope commented 4 years ago

Extending it has no meaning because it's only used in compiling

Sorry didn't catch your point. Typescript is only used in compiling, too.

The page is only used in plugin config and themeConfig for extendPage, and the extend result is PageComputed when we access them, so there is no need to extend Page interface, we shoukd just change the type as I suggested and extend Page Comput in some where alse, is this description clear?😅

meteorlxy commented 4 years ago

Not all extended properties will be treated as computed. If you want to add a property in both Page and PageComputed, try to extend BasePage

Mister-Hope commented 4 years ago

Not all extended properties will be treated as computed. If you want to add a property in both Page and PageComputed, try to extend BasePage

Emmm, an example please? Even in generated I am seeing PageComputed

meteorlxy commented 4 years ago
declare 'vuepress-types/types/page' {
  interface BasePage {
    foo: bar;
  }
}
Mister-Hope commented 4 years ago
declare 'vuepress-types/types/page' {
  interface BasePage {
    foo: bar;
  }
}

😅I was saying an example of user accessing Page interface somewhere in theme config, plugin config or components.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.