Coder Social home page Coder Social logo

Comments (17)

Hubro avatar Hubro commented on May 1, 2024 3

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.

SolarLiner avatar SolarLiner commented on May 1, 2024 2

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.

molefrog avatar molefrog commented on May 1, 2024 2

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.

Ty3uK avatar Ty3uK commented on May 1, 2024 1

@Hubro I've already creating PR to DefinitelyTyped with types for wouter/preact module. Stay tuned!

from wouter.

Ty3uK avatar Ty3uK commented on May 1, 2024

Also, @molefrog, maybe we can move typings inside this repo?

from wouter.

molefrog avatar molefrog commented on May 1, 2024

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.

molefrog avatar molefrog commented on May 1, 2024

@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.

Ty3uK avatar Ty3uK commented on May 1, 2024

@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.

molefrog avatar molefrog commented on May 1, 2024

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.

Ty3uK avatar Ty3uK commented on May 1, 2024

https://github.com/pixijs/pixi-typescript

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.

Ty3uK avatar Ty3uK commented on May 1, 2024

which isn't the case, right? I'm confused sorry

My bad, sorry

from wouter.

molefrog avatar molefrog commented on May 1, 2024

@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 avatar Hubro commented on May 1, 2024

@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.

Ty3uK avatar Ty3uK commented on May 1, 2024

I can make PR tomorrow

from wouter.

molefrog avatar molefrog commented on May 1, 2024

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.

cedeber avatar cedeber commented on May 1, 2024

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.

Ty3uK avatar Ty3uK commented on May 1, 2024

@cedeber @types/wouter already not necessary since #51

from wouter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.