Skip to content

Commit

Permalink
fix(di): correct typings for withRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt authored and awinogradov committed Dec 18, 2018
1 parent 117a428 commit a79eca2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/di/di.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as React from 'react';
import { createContext } from 'react';
import React, { StatelessComponent, ComponentType, createContext } from 'react';

export type GetNonDefaultProps<T> = T extends {} ? never : T;
export type RegistryContext = Record<string, Registry>;

const registryContext = createContext<RegistryContext>({});
const RegistryProvider = registryContext.Provider;

export const RegistryConsumer = registryContext.Consumer;

export function withRegistry<P>(...registries: Registry[]) {
return function WithRegistry(Component: React.ComponentType<P>) {
const RegistryResolver: React.SFC<P> = (props: P) => {
export function withRegistry(...registries: Registry[]) {
return function WithRegistry<P>(Component: ComponentType<P>) {
const RegistryResolver: StatelessComponent<GetNonDefaultProps<P>> = (props: P) => {
return (
<RegistryConsumer>
{contextRegistries => {
Expand Down Expand Up @@ -62,7 +62,7 @@ export class Registry {
* @param id component id
* @param component valid react component
*/
set<T>(id: string, component: React.ComponentType<T>) {
set<T>(id: string, component: ComponentType<T>) {
this.components.set(id, component);

return this;
Expand All @@ -73,7 +73,7 @@ export class Registry {
*
* @param id component id
*/
get<T>(id: string): React.ComponentType<T> {
get<T>(id: string): ComponentType<T> {
if (__DEV__) {
if (!this.components.has(id)) {
throw new Error(`Component with id '${id}' not found.`);
Expand Down

0 comments on commit a79eca2

Please sign in to comment.