fix(types): augment ref unwrap bail types in appropriate packages
Packages can now augment the ref unwrap bail types in their own `d.ts`. Also updated the build script to auto concat any files in a package's `types` directory to the final generated `d.ts`. - `@vue/reactivity` should no longer require `libs: ["DOM"]` in tsconfig - Properly bail on `VNode` and `ComponentPublicInstance` in runtime-core
This commit is contained in:
@@ -9,7 +9,8 @@ export {
|
||||
triggerRef,
|
||||
Ref,
|
||||
UnwrapRef,
|
||||
ToRefs
|
||||
ToRefs,
|
||||
RefUnwrapBailTypes
|
||||
} from './ref'
|
||||
export {
|
||||
reactive,
|
||||
|
||||
@@ -139,13 +139,37 @@ export function toRef<T extends object, K extends keyof T>(
|
||||
// corner case when use narrows type
|
||||
// Ex. type RelativePath = string & { __brand: unknown }
|
||||
// RelativePath extends object -> true
|
||||
type BaseTypes = string | number | boolean | Node | Window
|
||||
type BaseTypes = string | number | boolean
|
||||
|
||||
/**
|
||||
* This is a special exported interface for other packages to declare
|
||||
* additional types that should bail out for ref unwrapping. For example
|
||||
* \@vue/runtime-dom can declare it like so in its d.ts:
|
||||
*
|
||||
* ``` ts
|
||||
* declare module '@vue/reactivity' {
|
||||
* export interface RefUnwrapBailTypes {
|
||||
* runtimeDOMBailTypes: Node | Window
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* Note that api-extractor somehow refuses to include `decalre module`
|
||||
* augmentations in its generated d.ts, so we have to manually append them
|
||||
* to the final generated d.ts in our build process.
|
||||
*/
|
||||
export interface RefUnwrapBailTypes {}
|
||||
|
||||
export type UnwrapRef<T> = T extends ComputedRef<infer V>
|
||||
? UnwrapRefSimple<V>
|
||||
: T extends Ref<infer V> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>
|
||||
|
||||
type UnwrapRefSimple<T> = T extends Function | CollectionTypes | BaseTypes | Ref
|
||||
type UnwrapRefSimple<T> = T extends
|
||||
| Function
|
||||
| CollectionTypes
|
||||
| BaseTypes
|
||||
| Ref
|
||||
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
|
||||
? T
|
||||
: T extends Array<any> ? T : T extends object ? UnwrappedObject<T> : T
|
||||
|
||||
|
||||
Reference in New Issue
Block a user