Skip to content

fix: avoid accessing undeclared instance fields on type level #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/component/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export type ComponentRenderProxy<P = {}, S = {}, PublicProps = P> = {
S;

// for Vetur and TSX support
type VueConstructorProxy<PropsOptions, RawBindings> = {
new (): ComponentRenderProxy<
type VueConstructorProxy<PropsOptions, RawBindings> = VueConstructor & {
new (...args: any[]): ComponentRenderProxy<
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified this type as it cannot match existing typings which expects VueConstructor like vue-router. By writing argument as (...args: any[]), we can mix it with the intersected constructor so that ComponentRenderProxy retains even after inherit VueConstructor.

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html

This probably fixes #185 ?

ExtractPropTypes<PropsOptions>,
UnwrapRef<RawBindings>,
ExtractPropTypes<PropsOptions, false>
Expand Down Expand Up @@ -65,15 +65,15 @@ interface ComponentOptionsWithProps<
setup?: SetupFunction<Props, RawBindings>;
}

interface ComponentOptionsWithoutProps<Props = never, RawBindings = Data> {
interface ComponentOptionsWithoutProps<Props = unknown, RawBindings = Data> {
props?: undefined;
setup?: SetupFunction<Props, RawBindings>;
}

// overload 1: object format with no props
export function createComponent<RawBindings>(
options: ComponentOptionsWithoutProps<never, RawBindings>
): VueProxy<never, RawBindings>;
options: ComponentOptionsWithoutProps<unknown, RawBindings>
): VueProxy<unknown, RawBindings>;
// overload 2: object format with object props declaration
// see `ExtractPropTypes` in ./componentProps.ts
export function createComponent<
Expand Down
2 changes: 1 addition & 1 deletion test/types/createComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('createComponent', () => {
const App = createComponent({
setup(props, ctx) {
isTypeEqual<SetupContext, typeof ctx>(true);
isTypeEqual<never, typeof props>(true);
isTypeEqual<unknown, typeof props>(true);
return () => null;
},
});
Expand Down