/error.txt Secret
Created
March 4, 2018 11:14
type issue - preact-async-route
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tests/ts/index.tsx(18,25): error TS2322: Type '{ path: string; component: typeof Router; }' is not assignable to type 'IAsyncRouteProps & ComponentProps<AsyncRoute>'. | |
Type '{ path: string; component: typeof Router; }' is not assignable to type 'IAsyncRouteProps'. | |
Types of property 'component' are incompatible. | |
Type 'typeof Router' is not assignable to type 'ComponentConstructor | FunctionalComponentConstructor'. | |
Type 'typeof Router' is not assignable to type 'FunctionalComponentConstructor'. | |
Type 'Router' is not assignable to type 'FunctionalComponent<C>'. | |
Type 'Router' provides no match for the signature '(props?: C & ComponentProps<FunctionalComponent<C>>, context?: any): Element'. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, FunctionalComponent } from 'preact'; | |
type ComponentConstructor = { | |
new<A, B>() : Component<A, B>; | |
} | |
type FunctionalComponentConstructor = { | |
new<C>() : FunctionalComponent<C>; | |
} | |
interface IAsyncRouteProps { | |
component?: ComponentConstructor | FunctionalComponentConstructor; | |
getComponent?: ( | |
this: AsyncRoute, | |
url: string, | |
callback: (component: ComponentConstructor | FunctionalComponentConstructor) => void, | |
props: any | |
) => Promise<any> | void; | |
loading?: () => JSX.Element; | |
} | |
export default class AsyncRoute extends Component<IAsyncRouteProps, {}> { | |
public render(): JSX.Element | null; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { h, render, Component } from 'preact'; | |
import Router from 'preact-router'; | |
import AsyncRoute from '../../'; | |
/** | |
* This dummy component is used to catch TypeScript | |
* type issues via the TypeScript compiler. | |
*/ | |
function componentFetcher(url: string, cb: (c: any) => void, props: any): Promise<any> | void {} | |
function loadingAnimation(): JSX.Element | any { | |
return <div></div>; | |
} | |
export class Index extends Component<{}, {}> { | |
public render(): JSX.Element { | |
return <Router>// ↓ - Type error here | |
<AsyncRoute path="/" component={Router} /> | |
<AsyncRoute path="/" getComponent={componentFetcher} /> | |
<AsyncRoute path="/" getComponent={componentFetcher} loading={loadingAnimation} /> | |
</Router>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make sure that
Router
really has a constructor of the appropriate signature. Maybe it takes more value parameters etc. I noticed from the React type definitions that the Component constructor is defined like this: