Skip to content

Commit

Permalink
fix: avoid accessing undeclared instance fields on type level (vuejs#189
Browse files Browse the repository at this point in the history
)

* fix: avoid accessing undeclared instance fields on type level

* fix: inherit vue constructor type for constructor proxy

fix vuejs#187 
fix vuejs#185
  • Loading branch information
ktsn authored and pikax committed Apr 19, 2020
1 parent af1dd40 commit 391f1a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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<
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

0 comments on commit 391f1a1

Please sign in to comment.