types(@vant/use): improve Ref param typing
This commit is contained in:
@@ -31,7 +31,7 @@ export default {
|
||||
### 类型定义
|
||||
|
||||
```ts
|
||||
function useRect((Element | Window) | Ref<Element | Window>): DOMRect;
|
||||
function useRect((Element | Window) | Ref<Element | Window | undefined>): DOMRect;
|
||||
```
|
||||
|
||||
### 返回值
|
||||
|
||||
@@ -5,7 +5,7 @@ function isWindow(val: unknown): val is Window {
|
||||
}
|
||||
|
||||
export const useRect = (
|
||||
elementRef: (Element | Window) | Ref<Element | Window>
|
||||
elementRef: (Element | Window) | Ref<Element | Window | undefined>
|
||||
) => {
|
||||
const element = unref(elementRef);
|
||||
|
||||
@@ -23,7 +23,7 @@ export const useRect = (
|
||||
};
|
||||
}
|
||||
|
||||
if (element.getBoundingClientRect) {
|
||||
if (element && element.getBoundingClientRect) {
|
||||
return element.getBoundingClientRect();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user