diff --git a/CHANGELOG.md b/CHANGELOG.md index 50d590af..7ff029db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ + +## [1.4.8](https://github.com/vuejs/composition-api/compare/v1.4.7...v1.4.8) (2022-02-26) + + +### Bug Fixes + +* **types:** optional Boolean props as default props ([#909](https://github.com/vuejs/composition-api/issues/909)) ([8f88ae6](https://github.com/vuejs/composition-api/commit/8f88ae6)) +* use registered Vue instance for warning ([b01f1e4](https://github.com/vuejs/composition-api/commit/b01f1e4)) + + + ## [1.4.7](https://github.com/vuejs/composition-api/compare/v1.4.6...v1.4.7) (2022-02-24) diff --git a/README.md b/README.md index 956a603f..0144a561 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Include `@vue/composition-api` after Vue and it will install itself automaticall ```html - + ``` diff --git a/README.zh-CN.md b/README.zh-CN.md index c6651f62..6cc16871 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -40,7 +40,7 @@ import { ref, reactive } from '@vue/composition-api' ```html - + ``` diff --git a/package.json b/package.json index 8a0fbf98..5445e7e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vue/composition-api", - "version": "1.4.7", + "version": "1.4.8", "description": "Provide logic composition capabilities for Vue.", "keywords": [ "vue", diff --git a/src/component/componentProps.ts b/src/component/componentProps.ts index ed51d579..f66af446 100644 --- a/src/component/componentProps.ts +++ b/src/component/componentProps.ts @@ -76,7 +76,19 @@ export type ExtractPropTypes = O extends object : { [K in string]: any } type DefaultKeys = { - [K in keyof T]: T[K] extends { default: any } ? K : never + [K in keyof T]: T[K] extends + | { + default: any + } + | BooleanConstructor + | { type: BooleanConstructor } + ? T[K] extends { + type: BooleanConstructor + required: true + } + ? never + : K + : never }[keyof T] // extract props which defined with default from prop options diff --git a/src/runtimeContext.ts b/src/runtimeContext.ts index e076eac2..cc43b5ad 100644 --- a/src/runtimeContext.ts +++ b/src/runtimeContext.ts @@ -9,7 +9,7 @@ import { UnionToIntersection, isFunction, } from './utils' -import Vue$1 from 'vue' +import type Vue$1 from 'vue' let vueDependency: VueConstructor | undefined = undefined diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 60f72a1d..9b715714 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,4 +1,4 @@ -import Vue from 'vue' +import { getRegisteredVueOrDefault } from '../runtimeContext' const toString = (x: any) => Object.prototype.toString.call(x) @@ -99,7 +99,9 @@ export function isUndef(v: any): boolean { } export function warn(msg: string, vm?: Vue) { - Vue.util.warn(msg, vm) + const Vue = getRegisteredVueOrDefault() + if (!Vue || !Vue.util) console.warn(`[vue-composition-api] ${msg}`) + else Vue.util.warn(msg, vm) } export function logError(err: Error, vm: Vue, info: string) { diff --git a/test/v3/runtime-core/apiWatch.spec.ts b/test/v3/runtime-core/apiWatch.spec.ts index f71bcd05..57dc6335 100644 --- a/test/v3/runtime-core/apiWatch.spec.ts +++ b/test/v3/runtime-core/apiWatch.spec.ts @@ -8,11 +8,12 @@ import { shallowReactive, nextTick, } from '../../../src' -import Vue from 'vue' +import { getRegisteredVueOrDefault } from '../../../src/runtimeContext' // reference: https://vue-composition-api-rfc.netlify.com/api.html#watch describe('api: watch', () => { + const Vue = getRegisteredVueOrDefault() // const warnSpy = jest.spyOn(console, 'warn'); const warnSpy = jest.spyOn((Vue as any).util, 'warn')