Skip to content

Instantly share code, notes, and snippets.

@milesj
Created April 30, 2018 17:19
Show Gist options
  • Save milesj/fa5a291874bf5c15c1b0e0e3fa894024 to your computer and use it in GitHub Desktop.
Save milesj/fa5a291874bf5c15c1b0e0e3fa894024 to your computer and use it in GitHub Desktop.
TS function interface inferrence
import React from 'react';
interface ComponentProps {}
// Inferred, don't need to do anything (preferred)
function Component(props: ComponentProps) {}
// Using "this" special argument, but this does not support static properties or methods
function Component(this: React.SFC<ComponentProps>, props: ComponentProps) {}
// Using a special "static" argument (or something similar)
function Component(static: React.SFC<ComponentProps>, props: ComponentProps) {}
// Explicitly casting using "as"
function Component(props: ComponentProps) {} as React.SFC<ComponentProps>;
export default Component;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment