Skip to content

Commit 396c946

Browse files
committed
type: modify Default type issue. #50
1 parent 6dd9df9 commit 396c946

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

core/README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,16 @@ export declare const If: FC<PropsWithChildren<IfProps>>;
182182
## `<Switch />` `<Case />` `<Default />` Props
183183

184184
```tsx
185-
import { type FC, type PropsWithChildren } from 'react';
186-
export declare const Switch: FC<PropsWithChildren<{}>>;
187-
185+
import type { FC, PropsWithChildren } from 'react';
186+
export const Switch: FC<PropsWithChildren<{}>>;
188187
type TagType = React.ElementType | keyof JSX.IntrinsicElements;
189188
interface CaseElementProps<T extends TagType> {
190189
as?: T;
191190
readonly condition?: boolean;
192191
}
193192
export type CaseProps<T extends TagType> = CaseElementProps<T> & React.ComponentPropsWithoutRef<T>;
194-
export declare const Case: <T extends TagType>(props: CaseProps<T>) => null;
195-
export declare const Default: <T extends TagType>(props: CaseProps<T>) => null;
193+
export const Case: <T extends TagType>(props: CaseProps<T>) => any;
194+
export const Default: <T extends TagType>(props: Omit<CaseProps<T>, 'condition'>) => import("react/jsx-runtime").JSX.Element;
196195
```
197196

198197
## Development

core/src/switch.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const Switch: FC<PropsWithChildren<{}>> = ({ children }) => {
2020
}
2121
return false;
2222
});
23-
return <>{matchChild ?? defaultCase ?? null}</>;
23+
return matchChild ?? defaultCase ?? null;
2424
};
2525

2626
type TagType = React.ElementType | keyof JSX.IntrinsicElements;
@@ -37,4 +37,6 @@ export const Case = <T extends TagType>(props: CaseProps<T>) => {
3737
return Elm ? <Elm {...reset}>{children}</Elm> : children;
3838
};
3939

40-
export const Default = <T extends TagType>(props: CaseProps<T>) => <Case {...props} />;
40+
export const Default = <T extends TagType>(props: Omit<CaseProps<T>, 'condition'>) => (
41+
<Case {...({ ...props } as CaseProps<T>)} />
42+
);

core/switch.d.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
declare module '@uiw/react-only-when/switch' {
2-
import { FC, PropsWithChildren } from 'react';
3-
export declare const Switch: <T extends TagType>({ children }: PropsWithChildren) => null;
2+
import type { FC, PropsWithChildren } from 'react';
3+
export const Switch: FC<PropsWithChildren<{}>>;
44
type TagType = React.ElementType | keyof JSX.IntrinsicElements;
55
interface CaseElementProps<T extends TagType> {
66
as?: T;
77
readonly condition?: boolean;
88
}
99
export type CaseProps<T extends TagType> = CaseElementProps<T> & React.ComponentPropsWithoutRef<T>;
10-
export declare const Case: <T extends TagType>(props: CaseProps<T>) => any;
11-
export declare const Default: <T extends TagType>(props: CaseProps<T>) => any;
10+
export const Case: <T extends TagType>(props: CaseProps<T>) => any;
11+
export const Default: <T extends TagType>(
12+
props: Omit<CaseProps<T>, 'condition'>,
13+
) => import('react/jsx-runtime').JSX.Element;
1214
}

0 commit comments

Comments
 (0)