wix-incubator / obsidian

Dependency injection library for React and React Native applications
https://wix-incubator.github.io/obsidian/
105 stars 2 forks source link

Introduce an ESLint rule that ensures injected components are typed properly #161

Closed guyca closed 4 months ago

guyca commented 4 months ago

This PR introduces a new ESLint rule: strongly-typed-inject-component. The new rule ensures that functional components that are injected with the injectComponent HOC, are strongly typed.

Incorrect Correct
```ts import {injectComponent} from 'react-obsidian'; type Own = { name: string; }; type Injected = { bar: Bar; }; const _Foo = (props: Own & Injected) => { return null; }; export const Foo = injectComponent(_Foo, SomeGraph); ``` ```ts import {injectComponent} from 'react-obsidian'; type Own = { name: string; }; type Injected = { bar: Bar; }; const _Foo = (props: Own & Injected) => { return null; }; // The rule enforces the correct types are passed to the injectComponent HOC export const Foo = injectComponent(_Foo, SomeGraph); ```