Skip to content
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

TypeScript: can't pass default value to "t" as second argument #1198

Closed
maksis opened this issue Feb 9, 2019 · 4 comments
Closed

TypeScript: can't pass default value to "t" as second argument #1198

maksis opened this issue Feb 9, 2019 · 4 comments

Comments

@maksis
Copy link

maksis commented Feb 9, 2019

Using t('key', 'Default value') (as documented in https://www.i18next.com/translation-function/essentials#passing-a-default-value) currently causes the following error:

Argument of type '"Default value"' is not assignable to parameter of type 'TOptions<object> | undefined'.

I'm using version 14.1.1

@rosskevin
Copy link
Collaborator

rosskevin commented Feb 13, 2019

@jamuhl are the docs wrong? I see defaultValue as a key in the options, so ts would allow:

i18next.t('key', {defaultValue: 'default value to show'});

but not:

i18next.t('key', 'default value to show');

@rosskevin
Copy link
Collaborator

I don't spot the case where the string defaultValue as a second arg is allowed/tested in https://github.com/i18next/i18next/blob/master/test/translator/translator.translate.defaultValue.spec.js

@jamuhl
Copy link
Member

jamuhl commented Feb 13, 2019

both is allowed...having second function argument a string it's used as defaultValue using https://github.com/i18next/i18next/blob/master/src/Translator.js#L66

which defaults to https://github.com/i18next/i18next/blob/master/src/defaults.js#L39

@jamuhl
Copy link
Member

jamuhl commented Feb 13, 2019

new tests do not yet cover all cases - that's the reason why we run the old compatibility tests...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants