-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@bem-react/di: Check type when setting values in registry #386
Labels
Comments
В таком кейсе, нужно и сразу наверное подумать о переопределениях (например эксперименте). На ум приходит дешёвое решение: const expRegistry = new Registry<Partial<RegistryComponents>>({ id: 'registry-id' }) И немного дороже const expRegistry = new RegistryLayer<RegistryComponents>({ id: 'registry-id' }) Но возможно будет польза в каких-то подкапотных операций. |
@yarastqt у меня вроде хорошие новости interface IComponent { className: string }
interface IEnhancedComponent extends IComponent { prop: string }
interface IOtherComponent { prop: number }
interface IRegistry { Component: IComponent }
const registry: Partial<IRegistry> = {}
const Component: IComponent = { className: '' }
const EnhancedComponent: IEnhancedComponent = { className: '', prop: '' }
const OtherComponent: IOtherComponent = { prop: 35 }
registry.Component = Component; // OK
registry.Component = EnhancedComponent; // OK
registry.Component = OtherComponent; // TS ERROR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Неплохо было бы добавить проверку типов при установлении значений в реестре:
Но могут возникнуть проблемы при переопределении уже существующего реестра:
The text was updated successfully, but these errors were encountered: