Skip to content

Commit

Permalink
fix(di): return type in GetNonDefaultProps without GetNonDefaultProps
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt committed May 27, 2019
1 parent 3f92d39 commit 9f3ab8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 1 addition & 3 deletions packages/di/di.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React, {
ReactNode,
StatelessComponent,
FC,
ComponentType,
createContext,
useContext,
} from 'react';

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

const registryContext = createContext<RegistryContext>({});
Expand All @@ -17,7 +15,7 @@ export const RegistryConsumer = registryContext.Consumer;

export function withRegistry(...registries: Registry[]) {
return function WithRegistry<P>(Component: ComponentType<P>) {
const RegistryResolver: StatelessComponent<GetNonDefaultProps<P>> = (props: P) => {
const RegistryResolver: FC<P> = props => {
return (
<RegistryConsumer>
{contextRegistries => {
Expand Down
13 changes: 12 additions & 1 deletion packages/di/test/di.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tslint:disable no-shadowed-variable
import React from 'react';
import { describe, it } from 'mocha';
import { expect } from 'chai';
import { expect, assert } from 'chai';
import { render } from 'enzyme';

import {
Expand All @@ -12,6 +12,7 @@ import {
useRegistries,
useComponentRegistry,
} from '../di';
import { compose } from '../../core/core';

interface ICommonProps {
className?: string;
Expand Down Expand Up @@ -344,5 +345,15 @@ describe('@bem-react/di', () => {
expect(render(<Compositor/>).text()).eq('content');
});
});

describe('compose', () => {
it('should return correct type after composition', () => {
const componentRegistry = new Registry({ id: 'Component' });
const Component = (props: ICommonProps) => null;
const EnhancedComponent = compose(withRegistry(componentRegistry))(Component);
<EnhancedComponent className="hello" />;
assert(true);
});
});
});
});

0 comments on commit 9f3ab8e

Please sign in to comment.