New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wouter isn't compatible with TypeScript and Preact at the same time #49
Comments
@Hubro I've already creating PR to DefinitelyTyped with types for |
Also, @molefrog, maybe we can move typings inside this repo? |
Thanks @Ty3uK, appreciate the help!
I'm not super proficient in typings, but aren't they supposed to live in I think I read somewhere that unless your project is written in TS, you shouldn't put types next to our source files (not 100% sure). |
@Ty3uK Here is what other projects do: they have a separate repo with types, which they sync with DT on every release. I don't mind having that at all!
|
@molefrog as I know, recommended approach is store TypeScript typings with source code or generate them from Flow typings with prepublish hook. Also, there is a quote from DefinitelyTyped:
|
Alright, the quote says:
which isn't the case, right? I'm confused sorry 😕 |
Also there:
Prior to version 5.0 of PixiJS, there were no native types, so the community had to create a separate repository |
My bad, sorry |
Yeah, my understanding is that DefinitelyTyped is a collection of typings for libraries that lack type information. If you can ship up-to-date typescript typings with your repository, that is definitely preferred. |
Just tested by creating import { ComponentType, FunctionComponent, VNode, ComponentChildren, AnyComponent } from "preact";
export type Params = { [paramName: string]: string } | null;
export type Path = string;
export type PushCallback = (to: string) => void;
export type LocationTuple = [Path, PushCallback];
export type Match = [boolean, Params];
export type MatcherFn = (pattern: string, path: Path) => Match;
export interface RouteProps {
children?: ((params: Params) => VNode) | VNode;
path: Path;
component?: ComponentType<any>;
match?: boolean;
}
export const Route: FunctionComponent<RouteProps>;
export interface LinkProps {
to?: string;
href?: string;
children: ComponentChildren;
onClick?: () => void;
}
export const Link: FunctionComponent<LinkProps>;
export interface RedirectProps {
to?: string;
href?: string;
}
export const Redirect: FunctionComponent<RedirectProps>;
export interface SwitchProps {
location?: string;
children: Array<AnyComponent<RouteProps>>;
}
export const Switch: FunctionComponent<SwitchProps>;
export interface RouterProps {
hook: () => LocationTuple;
matcher: MatcherFn;
}
export const Router: FunctionComponent<
Partial<RouterProps> & {
children: ComponentChildren;
}
>;
export function useRouter(): RouterProps;
export function useRoute(pattern: string): Match;
export function useLocation(): LocationTuple; (EDIT: For some reason VS Code didn't register my copy command, pasted the original type definition... 🤨) |
@molefrog Yeah, I believe you just make a |
I can make PR tomorrow |
Wow, what a team work guys. @Hubro thanks for the reference, I now feel more confident about the structure. And seems like we gonna have types quite soon 😄 |
If the pull request #55 is merged, there will be 2 different |
Hey @Hubro and everyone in the thread, We have just published a new version of wouter which comes with a standalone Preact package. Just replace - "wouter": "^2.1.1",
- "@types/wouter": "^2.0.1",
+ "wouter-preact": ^2.2.0" This package now has proper peer deps and doesn't rely on React anymore. And finally it comes with TS bundled in the package, so no need to use DT. Hope it works, looking forward for feedback! |
Wouter can't be used with TypeScript and Preact at the same time.
If you install
@types/wouter
, that also installs@types/react
, which conflicts with and breaks type definitions for preact.It (probably) works if you use
preact-compat
, but at that point you're not really "compatible with preact" in my opinion.A possible fix would be to push an alternative
@types/wouter-preact
that worked with Preact's type definitions.CC @StrayFromThePath - Thought this would be relevant for you.
The text was updated successfully, but these errors were encountered: