Skip to content

Instantly share code, notes, and snippets.

@sar
Created March 22, 2021 04:35
Show Gist options
  • Save sar/2ee1947076d4d6b2b9d47ccc6e106638 to your computer and use it in GitHub Desktop.
Save sar/2ee1947076d4d6b2b9d47ccc6e106638 to your computer and use it in GitHub Desktop.
Quick guide on constructing TypeScript @decorators

TypeScript Decorators

Wrapping typeof React.Component || React.ComponentType

function UsefulDecorator<T extends new (...args) => any>(
    BaseClass: T,
): T {
    return class _usefulClass extends BaseClass {
        private _someStore: typeof SomeStore = SomeStore;
        addtionalProp = 0;

        public render() {
            return <BaseClass {...this.props} />;
        }
    };
}

export default UsefulDecorator;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment