-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: export type helpers for components and hooks
- Loading branch information
Showing
9 changed files
with
76 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './components' | ||
export * from './hooks' | ||
export * from './types' | ||
export * from './utils' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { LinkProps as _LinkProps, NavigateOptions as NavOptions, NavigateProps as NavProps } from 'react-router-dom' | ||
|
||
export type To<Pathname = string> = { pathname: Pathname; search?: string; hash?: string } | ||
|
||
type ComponentProps<Path extends string | To, Params extends Record<string, any>> = Path extends keyof Params | ||
? { to: Path; params: Params[Path] } | ||
: Path extends { pathname: infer Pathname } | ||
? Pathname extends keyof Params | ||
? { to: To<Pathname>; params: Params[Pathname] } | ||
: { to: To<Pathname>; params?: never } | ||
: { to: Path; params?: never } | ||
|
||
export type LinkProps<Path extends string | To, Params extends Record<string, any>> = Omit<_LinkProps, 'to'> & | ||
ComponentProps<Path, Params> | ||
|
||
export type NavigateProps<Path extends string | To, Params extends Record<string, any>> = Omit<NavProps, 'to'> & | ||
ComponentProps<Path, Params> | ||
|
||
export type NavigateOptions<Path extends string | To | number, Params extends Record<string, any>> = Path extends number | ||
? [] | ||
: Path extends keyof Params | ||
? [NavOptions & { params: Params[Path] }] | ||
: Path extends { pathname: infer Pathname } | ||
? Pathname extends keyof Params | ||
? [NavOptions & { params: Params[Pathname] }] | ||
: [NavOptions & { params?: never }] | [] | ||
: [NavOptions & { params?: never }] | [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './components' | ||
export * from './hooks' | ||
export * from './types' | ||
export * from './utils' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { AnchorProps as AProps, NavigateOptions as NavOptions, NavigateProps as NavProps } from '@solidjs/router' | ||
|
||
type ComponentProps<Path extends string, Params extends Record<string, any>> = Path extends keyof Params | ||
? { href: Path; params: Params[Path] } | ||
: { href: Path; params?: never } | ||
|
||
export type AnchorProps<Path extends string, Params extends Record<string, any>> = Omit<AProps, 'href'> & | ||
ComponentProps<Path, Params> | ||
|
||
export type NavigateProps<Path extends string, Params extends Record<string, any>> = Omit<NavProps, 'href'> & | ||
ComponentProps<Path, Params> | ||
|
||
export type NavigateOptions<Path extends string, Params extends Record<string, any>> = Path extends keyof Params | ||
? [Partial<NavOptions> & { params: Params[Path] }] | ||
: [Partial<NavOptions> & { params?: never }] | [] |