-
-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parameterized use of TFunction fails while WithT use works (#1188)
* Parameterized use of TFunction fails while WithT use works * rename tests * use simple type declaration for TFunction - allows for external parameterized use * fix lint error and add new test with optional arg * Using typescript scrict, it appears undefined must be in the TResult to play nice with optional args/props
- Loading branch information
Showing
5 changed files
with
44 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import i18next from 'i18next'; | ||
|
||
/** | ||
* Use of the exported TFunction in external utility methods such as | ||
* NamespaceConsumer children t | ||
*/ | ||
function childrenNamespacesConsumer(t: i18next.TFunction, i18n: i18next.i18n) { | ||
// sanity first - tests from i18next t.test | ||
const is: string = i18n.t('friend'); // same as <string> | ||
const io: object = i18n.t<object>('friend'); | ||
const isa: string[] = i18n.t<string[]>('friend'); | ||
const ioa: object[] = i18n.t<object[]>('friend'); | ||
|
||
// (failing) now try t provided by NamespacesConsumer | ||
const s: string = t('friend'); // same as <string> | ||
const o: object = t<object>('friend'); | ||
const sa: string[] = t<string[]>('friend'); | ||
const oa: object[] = t<object[]>('friend'); | ||
} | ||
|
||
function callsMethodWithOptionalArg(t: i18next.TFunction, i18n: i18next.i18n) { | ||
function displayHint(hint?: string) { | ||
return String(hint); | ||
} | ||
displayHint(i18n.t('friend')); | ||
displayHint(t('friend')); | ||
} | ||
|
||
function callsMethodWithRequiredArg(t: i18next.TFunction, i18n: i18next.i18n) { | ||
function displayHint(hint: string) { | ||
return String(hint); | ||
} | ||
displayHint(i18n.t('friend')); | ||
displayHint(t('friend')); | ||
} |
File renamed without changes.