From 1383f6e24e384db0a9179f7ea6e40762f474233a Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Mon, 14 Dec 2020 23:49:33 +0900 Subject: [PATCH] fix(runtime-core): force evalutating SetupContext type (fix #2362) --- packages/runtime-core/src/component.ts | 15 +++++++++------ test-dts/component.test-d.ts | 12 +++++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 788a20b4343..9f52dbaed01 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -167,12 +167,15 @@ export const enum LifecycleHooks { ERROR_CAPTURED = 'ec' } -export interface SetupContext { - attrs: Data - slots: Slots - emit: EmitFn - expose: (exposed: Record) => void -} +// use `E extends any` to force evaluating type to fix #2362 +export type SetupContext = E extends any + ? { + attrs: Data + slots: Slots + emit: EmitFn + expose: (exposed: Record) => void + } + : never /** * @internal diff --git a/test-dts/component.test-d.ts b/test-dts/component.test-d.ts index 30b3b8e5f53..b314ba7880d 100644 --- a/test-dts/component.test-d.ts +++ b/test-dts/component.test-d.ts @@ -9,7 +9,9 @@ import { expectType, ShallowUnwrapRef, FunctionalComponent, - ComponentPublicInstance + ComponentPublicInstance, + SetupContext, + expectAssignable } from './index' declare function extractComponentOptions( @@ -423,3 +425,11 @@ describe('class', () => { expectType(props.foo) }) + +describe('SetupContext', () => { + describe('can assign', () => { + const wider: SetupContext<{ a: () => true; b: () => true }> = {} as any + + expectAssignable true }>>(wider) + }) +})