Comments (17)
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.
from wouter.
Just tested by creating preact/index.d.ts
inside the wouter folder in node_modules (on a personal project) - and it works. I've borrowed the contents from the top-level definitions, replacing with Preact imports instead. Here it is:
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... π€¨)
from wouter.
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
with wouter-preact
in your package json:
- "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!
from wouter.
@Hubro I've already creating PR to DefinitelyTyped with types for wouter/preact
module. Stay tuned!
from wouter.
Also, @molefrog, maybe we can move typings inside this repo?
from wouter.
Thanks @Ty3uK, appreciate the help!
maybe we can move typings inside this repo?
I'm not super proficient in typings, but aren't they supposed to live in DefinitelyTyped
repo? What I mean is if we had typings inside of the repo, we would still need to copy these files to DT in a PR whenever we want to update types, right?
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).
from wouter.
@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!
https://github.com/pixijs/pixi-typescript
This repository contains the most recent version of the declarations for pixi.js and follows the v4.x branch with periodical Releases which are supposed to match pixi releases by the core team.
from wouter.
@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:
If you are the library author and your package is written in TypeScript, bundle the autogenerated declaration files in your package instead of publishing to Definitely Typed.
from wouter.
Alright, the quote says:
If you are the library author and your package is written in TypeScript
which isn't the case, right? I'm confused sorry π
from wouter.
Also there:
Note This repository is not intended for v5.x which ships with its own generated declarations.
Prior to version 5.0 of PixiJS, there were no native types, so the community had to create a separate repository
from wouter.
which isn't the case, right? I'm confused sorry
My bad, sorry
from wouter.
@Hubro @Ty3uK Got it. So would the following file structure work?
- index.js
- ... other source files
- index.d.ts
- preact/
- index.js
- ...
- index.d.ts
Is there a special constraint on file names? Would it automatically fetch types if I just do import ... from "wouter"
in my ts?
from wouter.
@Hubro @Ty3uK Got it. So would the following file structure work?
index.js
... other source files
index.d.ts
preact/
- index.js
- ...
- index.d.ts
Is there a special constraint on file names? Would it automatically fetch types if I just do
import ... from "wouter"
in my ts?
@molefrog Yeah, I believe you just make a .d.ts
file for every .ts
file and you're good. Here's a project for reference: https://github.com/storeon/storeon
from wouter.
I can make PR tomorrow
from wouter.
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 π
from wouter.
If the pull request #55 is merged, there will be 2 different package.json
(one for wouter
and one for wouter/preact
) and it should solve this issue. I've added the types
property on both so the installation of @types/wouter
wonβt be necessary anymore for TypeScript.
from wouter.
@cedeber @types/wouter
already not necessary since #51
from wouter.
Related Issues (20)
- wouter-preact: Params with typescript? HOT 2
- How to add params in a nesting route? HOT 3
- v2.12.1 npm package is out of sync with v2.12.1 tag HOT 1
- v3.0.0-rc.1: When use hash router, Ctrl+click on <Link>, new window is opened with wrong url HOT 3
- Potential `useSearch` bug not triggering updates when used with `urql` HOT 9
- [Bug] Can't match default <Route>Not found</Route> when Router inside Switch HOT 3
- (?) Hash routing with no prefix slash index.html#/example/path/ HOT 3
- useSearch unsafe parameter decoding HOT 3
- v3.0.0-rc.2 decodeUriComponent is called before route match, breaking links with urlencoded slash (%2F) HOT 2
- v3.0.0-rc.1: `useRoute` should allow `nest` option just like `<Route />` HOT 1
- Suggestion: `<Link>` should always render an `<a>` (or at least have the option to do so) HOT 5
- Accessing nested params with `useParams` HOT 8
- Nested routing broken by intermediate component HOT 2
- Exit animation with framer-motion HOT 7
- How to use V3 with Jest? HOT 3
- [BUG] `useHashLocation` not syncing with state HOT 3
- Docs don't say how to install; no readme on NPM page HOT 1
- import/no-unresolved eslint error being raised on Wouter 3.0.x HOT 3
- Intercept location change with custom hook swallows state HOT 2
- Components being unnecessarily remounted HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wouter.