Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses 2 problems with Typescript types:
$t
does not have TypeScript auto-completions #1215: By removing the typePath
from thekey: Key | ResourceKeys | Path
, we get type inference to work again and suggest valid translations when using globally injected$t
. Since the typeKey extends string
already extends fromstring
, it shouldn't cause any regression. For the type inference to work when using$t
, you have to extend the module types:en.json
locale file, type inference will suggest a combination of all keys:But this is not correct, only
this.is.a.nested.key
should be suggested. I've created two new types to solve this:JsonPaths
: Will return leaf keys only, and not suggest in-between keys from a JSON or Javascript object. I've called it Json because this should be used when extracting translations from JSON files.TranslationsPaths
: This will simply remove the first level of a JSON or JS object and return theJsonPaths
from the second level onwards. This is used for translations coming directly from the composer, where the top-level key is the language.I've tried not to modify existing types to avoid breaking something, and I just created these 2 new types. Here're two images of the new behavior both in
$t
and when using the composer: