Skip to content

Instantly share code, notes, and snippets.

@RoystonS
Created July 10, 2017 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoystonS/92784110dc263de4eea5329142badc5d to your computer and use it in GitHub Desktop.
Save RoystonS/92784110dc263de4eea5329142badc5d to your computer and use it in GitHub Desktop.
Sample complex file for parsing
Parsing stuff/TestComponent.ts
no tsconfig file specified - using default options
Component SimpleStatelessComponent:
bar: number
Component TestComponent:
children: ReactNode
thisIsAPropInASubtypeInterface: number
onSomething: (value: number) => void
thisIsAPropInABaseInterface: string
import * as React from 'react';
interface IMyPropsBase {
thisIsAPropInABaseInterface: string;
}
interface IMyProps extends IMyPropsBase {
thisIsAPropInASubtypeInterface: number;
onSomething(value: number): void;
}
interface ITheme {
}
interface IThemedProps {
theme: ITheme;
}
// A component which implements the IMyProps interface that I want
// to be public, but also accepts a theme property.
class MyComponent extends React.Component<IMyProps & IThemedProps, undefined> {
foobie: number;
}
// HoC function which takes a component with accepts props+themedprops and returns
// a component that just takes the props without the themedprops.
// (Dummy implementation that just returns its input)
function withTheme<ExternalProps, Theme>(
component: React.ComponentClass<ExternalProps & { theme: Theme }>
): React.ComponentClass<ExternalProps> {
return component;
}
interface IStatelessProps {
bar: number;
}
export function SimpleStatelessComponent(_props: IStatelessProps) {
return React.createElement('div');
}
export default withTheme<IMyProps, ITheme>(MyComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment