Skip to content

Instantly share code, notes, and snippets.

@FremyCompany
Created February 22, 2017 23:45
Show Gist options
  • Save FremyCompany/8dffc56b1b4265b915c5aae5e881bfd1 to your computer and use it in GitHub Desktop.
Save FremyCompany/8dffc56b1b4265b915c5aae5e881bfd1 to your computer and use it in GitHub Desktop.
Small helper to get autocompletion when authoring Mitrhil components in Typescript
function Component<T>(view: (attributes: T, children: Array<any>) => Mithril.VirtualElement): () => Mithril.Component<Mithril.ControllerWithAttributes<T>> & { attributes?: T} {
return () => ({ view(n) { return view(n.attributes, n.children); } } as any);
}
var Abc = Component<{ input:string, value:string }>(a =>
<div>{a.input}</div>
);
var t = <Abc input="true" value="true" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment