EugeneMeles / laravel-react-i18n

Allows to connect your `Laravel` Framework translation files with `React`.
MIT License
73 stars 8 forks source link

Typescript: Cannot invoke an object which is possibly 'undefined'. #7

Closed parth391 closed 1 year ago

TheCoati commented 1 year ago

I'm not sure why but in the interface the return type is optional. \ https://github.com/EugeneMeles/laravel-react-i18n/blob/c92cbf4a0bb45fa8cb577f9ee4211202754ef50e/src/interfaces/context.ts#L4

Therefore Typescript is throwing the error Cannot invoke an object which is possibly 'undefined' \ Using the following snippet will bypass this error.

t?.('translation')

It seems like the trans function that's called when using t can't return an optional value and is always string. https://github.com/EugeneMeles/laravel-react-i18n/blob/c92cbf4a0bb45fa8cb577f9ee4211202754ef50e/src/provider.ts#L121

EugeneMeles commented 1 year ago

Fixed at latest(2.0.0) version