Skip to content

Commit

Permalink
Merge pull request #576 from jmrog/typescript-functional-components
Browse files Browse the repository at this point in the history
Add TypeScript typings for functional components and inclusive components
  • Loading branch information
robertknight authored Apr 2, 2017
2 parents 9d9c232 + 2b19a3d commit 1efecfb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/preact.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ declare namespace preact {
}

interface FunctionalComponent<PropsType> {
(props?: PropsType & ComponentProps<this>, context?: any): JSX.Element
(props?:PropsType & ComponentProps<this>, context?:any):JSX.Element;
displayName?:string;
defaultProps?:any;
}

interface ComponentConstructor<PropsType, StateType> {
new (props?:PropsType, context?: any):Component<PropsType, StateType>;
}

// Type alias for a component considered generally, whether stateless or stateful.
type AnyComponent<PropsType, StateType> = FunctionalComponent<PropsType> | typeof Component;

abstract class Component<PropsType, StateType> implements ComponentLifecycle<PropsType, StateType> {
constructor(props?:PropsType, context?:any);

Expand All @@ -49,7 +54,7 @@ declare namespace preact {

state:StateType;
props:PropsType & ComponentProps<this>;
context: any;
context:any;
base:HTMLElement;

linkState:(name:string) => (event: Event) => void;
Expand All @@ -59,7 +64,7 @@ declare namespace preact {

forceUpdate(): void;

abstract render(props?:PropsType & ComponentProps<this>, state?:StateType, context?: any):JSX.Element;
abstract render(props?:PropsType & ComponentProps<this>, state?:StateType, context?:any):JSX.Element;
}

function h<PropsType>(node:ComponentConstructor<PropsType, any> | FunctionalComponent<PropsType>, params:PropsType, ...children:(JSX.Element|JSX.Element[]|string)[]):JSX.Element;
Expand Down

0 comments on commit 1efecfb

Please sign in to comment.