From e65e97b009b4e91886a66e9aafbf5286183dbc9a Mon Sep 17 00:00:00 2001 From: rudyxu Date: Thu, 28 Sep 2023 21:19:19 +0800 Subject: [PATCH] feat: remove `ExtractPropsAndEvents` util --- package.json | 2 +- src/componentOptions.ts | 6 ++++-- test-dts/defineComponent.test-d.tsx | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 3d81a49..be9d2b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-ts-utils", - "version": "0.2.1", + "version": "0.2.2", "description": "Typescript utils for Vue2 and Vue3", "main": "src/index.ts", "typings": "./lib/src/index.d.ts", diff --git a/src/componentOptions.ts b/src/componentOptions.ts index fc8e3c7..066cf03 100644 --- a/src/componentOptions.ts +++ b/src/componentOptions.ts @@ -2,7 +2,7 @@ import { Component, ComponentCustomOptions, ComponentInjectOptions, ComponentObj import { DebuggerHook, ErrorCapturedHook } from "./apiLifecycle" import { ComponentInternalInstance, ComponentInternalOptions, Data, SetupContext } from "./component"; import { EmitsToProps } from "./componentEmits" -import { CreateComponentPublicInstance } from './componentPublicInstance'; +import { ComponentPublicInstanceConstructor, CreateComponentPublicInstance } from './componentPublicInstance'; import { LooseRequired, UnionToIntersection, Prettify } from '@vue/shared' import { CompatConfig } from "./compatConfig"; import { SlotsType } from "./componentSlots"; @@ -12,7 +12,9 @@ type MergedHook void> = T | T[] declare const AttrSymbol: unique symbol export type AttrsType = Record> = { - [AttrSymbol]?: T + [AttrSymbol]?: T extends ComponentPublicInstanceConstructor + ? InstanceType['$props'] + : T } export type ExtractPropsAndEvents any> = InstanceType['$props']; export type UnwrapAttrsType< diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index 11c1369..cb8025a 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/test-dts/defineComponent.test-d.tsx @@ -1364,7 +1364,7 @@ describe('define attrs', () => { props: { bar: Number }, - attrs: Object as AttrsType>, + attrs: Object as AttrsType, created() { expectType(this.$attrs.class) expectType(this.$attrs.style) @@ -1481,7 +1481,7 @@ import { ComponentCustomProps, ExtractPropTypes } from './index' -import { AttrsType, ExtractPropsAndEvents } from 'src/componentOptions' +import { AttrsType } from 'src/componentOptions' // code generated by tsc / vue-tsc, make sure this continues to work // so we don't accidentally change the args order of DefineComponent