Skip to content
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

Initial typescript declarations and tests #144

Merged
merged 7 commits into from
Apr 12, 2018

Conversation

rosskevin
Copy link
Contributor

Closes #142

I have been using these definitions locally - so far so good.

Many of the types have been documented and are solid based on my use, though some of the others have been less traveled and are typed as any. While any is relevant in some situations, often it is bailing out. So these can be improved as we go.

In tests/typescript I have added the sample usage from the readme, as well as added the typescript script in for testing. This test-usage.tsx file can be expanded, or other files added to the directory as holes are found.

I think this setup should be fairly easy to keep up/validate. I expect others will find holes and PR small changes from here as well.

@taion
Copy link
Contributor

taion commented Dec 10, 2017

I’ve been on the road. Will look next week.

src/index.d.ts Outdated
*/
type TransitionHook = (
location: Location,
) => undefined | (boolean | string | Promise<boolean | string>)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the parens needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a matter of style, my local prettier formatted this so it is consistent

src/index.d.ts Outdated
[key: string]: any
}

function createBrowserRouter({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the spread/destructuring functionally do anything here? wouldn't be the same to do options: CreateBrowserRouterArgs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, it was when I copied in the signature. I'll remove

src/index.d.ts Outdated
// Improve these `any`s as needed
type FarceRouter = any

function createFarceRouter({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another one here :) why not making a type out of these args and use that instead of any?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted, this is a starting point. Feel free to enhance. I have typed everything I use (and more), now it's time for everyone to make it better.

@taion
Copy link
Contributor

taion commented Dec 12, 2017

@itajaja Do the definitions look good to you?

@itajaja
Copy link
Member

itajaja commented Dec 12, 2017

definitions are 👍 The only thing is that the ts test files are actually not used during CI, so there is a risk they'd go out of sync. The rest looks good!

@itajaja
Copy link
Member

itajaja commented Dec 12, 2017

maybe adding the typescript command during test would at lest validate the test files statically?

@rosskevin
Copy link
Contributor Author

@itajaja test script is already modified to execute typescript.

@taion
Copy link
Contributor

taion commented Dec 22, 2017

@rosskevin I'm sorry for the delay here. We've been really busy lately. I'm going to look to try to merge this next week.

src/index.d.ts Outdated
/**
* map version of search string
*/
query: Map
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a little stricter – it's string -> string

src/index.d.ts Outdated
*/
interface Match {
location: Location
params: Map
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a little stricter – it's string -> string (i think?)

src/index.d.ts Outdated
* Returns the path string for a pattern of the same format as a route path and a object of the
* corresponding path parameters
*/
format: (pattern: any, params: Map) => any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will support non-string things in params though

src/index.d.ts Outdated
/**
* Lenient arg version of location using in #push and #replace.
*/
type LocationArg = Pick<Location, 'pathname'> &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the union of this and "string" below is referred to as a "location descriptor" in the other docs: https://github.com/4Catalyzer/farce#locations-and-location-descriptors

src/index.d.ts Outdated
* Navigates to a new location
* @see farce
*/
public push: (location: string | LocationArg) => void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you define the arg here as a LocationDescriptor?

src/index.d.ts Outdated
* Navigates to a new location
* @see farce
*/
public push: (location: string | LocationArg) => void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually does return whatever the action dispatch returns, but i'm guessing you wouldn't want to use that return value

src/index.d.ts Outdated
*/
public go: (delta: number) => void

public createHref: Function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(location: LocationDescriptor) => string

src/index.d.ts Outdated
public go: (delta: number) => void

public createHref: Function
public createLocation: Function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(location: LocationDescriptor) => Location

src/index.d.ts Outdated
declare module 'found' {
import * as React from 'react'

interface Map {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it standard to call this Map? could this be ambiguous w/ES6 Map?

@rosskevin
Copy link
Contributor Author

Thanks for the review @taion - all look like good/appropriate changes. I'm underwater with some other efforts, I suggest merging and allowing other contributors to make it better. I'm pretty buried so feel free to do as you like, it's working for me for the last month so I don't have the impetus to pick it back up.

@taion
Copy link
Contributor

taion commented Dec 29, 2017

Yeah, same here, sorry. We can pick this up and try to get this merged soon.

@TomMarius
Copy link

Any news on this?

@unzico
Copy link

unzico commented Apr 11, 2018

@rosskevin Great work!
Since there hasn't been any update on this for a while: have you thought about contributing your definitions to the DefinitelyTyped project instead?

@taion
Copy link
Contributor

taion commented Apr 11, 2018

Gah I totally forgot about this.

@taion
Copy link
Contributor

taion commented Apr 12, 2018

I updated this PR to be mergeable again (including #174) and I addressed my own PR comments.

Can someone here take a look? If I can get a quick sign-off here, I'd be happy to merge and cut a release.

Copy link
Contributor Author

@rosskevin rosskevin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @taion

@taion taion merged commit 85fa24f into 4Catalyzer:master Apr 12, 2018
@rosskevin rosskevin deleted the typescript-definitions branch September 4, 2018 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants