Skip to content

Instantly share code, notes, and snippets.

@mthadley
Last active April 12, 2017 22:47
Show Gist options
  • Save mthadley/6a76b8b136f10624fbccb7480830e48a to your computer and use it in GitHub Desktop.
Save mthadley/6a76b8b136f10624fbccb7480830e48a to your computer and use it in GitHub Desktop.
// Type Defs
declare namespace JSX {
interface ElementAttributesProperty {
props;
}
}
interface ConfigAttr<T> {
valueFn: () => T;
value: T;
}
type Config<T> = {
[K in keyof T]: Partial<ConfigAttr<T[K]>>;
}
declare class Component<T, U> {
props: T;
state: U;
protected created(): void;
protected attached(): void;
protected detached(): void;
protected disposed(): void;
render(): any;
}
// Child
interface Props {
name: string;
label?: string;
}
interface State {
count: number;
page: number;
}
class Thing extends Component<Props, State> {
static STATE: Config<State>;
static PROPS: Config<Props>;
created() {
return 3;
}
doThing() {
this.state.count;
}
}
Thing.PROPS = {
name: {},
label: {
value: 'neato'
}
}
Thing.STATE = {
count: {
value: 3
},
page: {
value: 4
}
};
// Parent
class Parent extends Component<{}, {}> {
render() {
return (
<div>
<Thing label="asd" name="3" />
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment