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

Add TypeScript typings #159

Merged
merged 2 commits into from
Jan 15, 2019
Merged

Add TypeScript typings #159

merged 2 commits into from
Jan 15, 2019

Conversation

frenzzy
Copy link
Member

@frenzzy frenzzy commented Oct 30, 2018

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Closes #101

@pradyuman, @dangmai, @anantoghosh, @gytisgreitai, @jtmthf, @tlaziuk, @Lodin would be cool if some of you guys could take a look, thanks in advance!

@codecov-io
Copy link

codecov-io commented Oct 30, 2018

Codecov Report

Merging #159 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #159   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           4      4           
  Lines         144    144           
  Branches       42     42           
=====================================
  Hits          144    144

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6319db3...54e8b40. Read the comment docs.

@gytisgreitai
Copy link

Well I'm a bit out of Typescript world, so some of those maybe rookie mistakes.

I've replaced version in package.json with "git+https://github.com/frenzzy/universal-router.git#54e8b4047b987a1e7d75f7e3a1588c02ea31e2a0" and here are some observations:

  1. VSCode compiles fine, shows bindings all ok
  2. yarn start when using react-scripts-ts fails with Module not found: Can't resolve 'universal-router'
  3. How do I do imports with default class export ? E.g. now I'm doing, is there a prettier way?:
import UniversalRouter from 'universal-router';
import { Route, Context } from 'universal-router';
  1. In Route the action param signature is as follows:
action?: (context: RouteContext<C, R> & C, params: Params) => R | Promise<R> | void

shouldn't context be optional? cause I can simply do action: () => (<Dashboard/>) and it does seem to work

@frenzzy
Copy link
Member Author

frenzzy commented Oct 31, 2018

Hey @gytisgreitai, thanks for your feedback!

  1. Cool! This is the main goal why I want to add typings to the package.
  2. The package requires compilation before usage, it is why you can't just use git url. Instead you have to do the following:
git clone https://github.com/frenzzy/universal-router.git
cd universal-router
git checkout typescript
yarn install
yarn build
cd dist
yarn link
cd ../../your-project-name
yarn link universal-router
yarn start
  1. Like this:
import UniversalRouter, { Route, Context } from 'universal-router';
  1. From TypeScript docs:

Optional Parameters in Callbacks

Don’t use optional parameters in callbacks unless you really mean it:

/* WRONG */
interface Fetcher {
    getObject(done: (data: any, elapsedTime?: number) => void): void;
}

This has a very specific meaning: the done callback might be invoked with 1 argument or might be invoked with 2 arguments. The author probably intended to say that the callback might not care about the elapsedTime parameter, but there’s no need to make the parameter optional to accomplish this – it’s always legal to provide a callback that accepts fewer arguments.

Do write callback parameters as non-optional:

/* OK */
interface Fetcher {
    getObject(done: (data: any, elapsedTime: number) => void): void;
}

@frenzzy frenzzy merged commit 5552279 into kriasoft:master Jan 15, 2019
@frenzzy frenzzy deleted the typescript branch January 15, 2019 18:22
@langpavel langpavel mentioned this pull request Apr 9, 2019
15 tasks
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.

Typescript Typings are out of date
3 participants