-
Notifications
You must be signed in to change notification settings - Fork 55
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
feat: createBaseRouter in TS #1022
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
/* eslint-disable max-classes-per-file */ | ||
import React from 'react'; | ||
|
||
import RedirectException from './RedirectException'; | ||
import { Match, RedirectOptions } from './typeUtils'; | ||
import { LocationDescriptor, Match, RedirectOptions } from './typeUtils'; | ||
|
||
class Redirect implements RedirectOptions { | ||
path?: string; | ||
|
||
to: string | ((match: Match) => LocationDescriptor); | ||
|
||
status?: number; | ||
|
||
class Redirect { | ||
constructor({ from, to, status }: RedirectOptions) { | ||
// @ts-ignore | ||
this.path = from; | ||
// @ts-ignore | ||
this.to = to; | ||
// @ts-ignore | ||
this.status = status; | ||
} | ||
|
||
|
@@ -32,4 +38,10 @@ if (__DEV__) { | |
(Redirect.prototype as any).isReactComponent = {}; | ||
} | ||
|
||
export default Redirect; | ||
// This actually doesn't extend a React.Component, but we need consumer to think that it does | ||
class RedirectType extends React.Component<RedirectOptions> { | ||
// @ts-ignore | ||
constructor(config: RedirectOptions); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know whether there's a better way to do this. The problem is i need consumer(the user of the library) to think this component There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is ok but maybe do: declare class RedirectType extends React.Component<RedirectOptions> {
constructor(config: RedirectOptions);
} with the declare which should make it just a type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, it works 😄 |
||
|
||
export default Redirect as unknown as RedirectType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to just declare fields on classes. Technically those are functional changes, but practically they should not change anything. I'm pretty sure the only difference is that
this
has those initialized asundefined
when creating the instance, which should not change anything