Enhance typescript type check #2867
Replies: 2 comments 1 reply
-
inject is deprecated and we recommend to use React.createContext instead,
which is strongly typed ootb.
…On Sat, 27 Mar 2021, 05:49 Amir Hossein Shekari, ***@***.***> wrote:
as you know, using the @Inject with typescript always cause some problem
for the programmers (see #1778
<#1778> and mobxjs/mobx-react#256
<mobxjs/mobx-react#256>)
so I decided to use a custom decorator for both inject and class
component props type checking
I use the solution mentioned here
<mobxjs/mobx-react#256 (comment)>
import { Component } from 'react';import { inject } from 'mobx-react';import { Stores } from ***@***.***'; // root store inteface
export class ComponentWithStore<IStores, IProps = {}, IStates = {}> extends Component<IProps, IStates> {
public get stores() {
return (this.props as any) as IStores;
}}
export const connect = (...args: Array<keyof Stores>) => inject(...args);
how about enhancing the @Inject decorator with this??
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2867>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBENA475MMJLOELJWDDTFVWYNANCNFSM4Z4R4YUA>
.
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
danielkcz
-
I think it's time to finish #2541 work, we can add dev warn firstly for progressive migrate and then separate |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
as you know, using the
@inject
with typescript always cause some problem for the programmers (see #1778 and mobxjs/mobx-react#256)so I decided to use a custom decorator for both
inject
and class componentprops
type checkingI use the solution mentioned here
how about enhancing the
@inject
decorator with this??Beta Was this translation helpful? Give feedback.
All reactions