types: Rework TFunction and translation key suggestions #1898
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.
Allow 'other-ns:some.key' syntax regardless of current namespace(s). However, we no longer provide these keys via TS autosuggestion, to not flood the suggestion box with these.
This uses the 'DisableSuggestion' helper type, which unfortunately allows any capital case prefix to the actual 'other-ns:' prefix.
For getFixedT with multiple namespaces, all the keys in these namespaces are now suggested without 'ns:' prefix. Using such a prefix is still possible, though.
Technically, we treat cases with a fixed single namespace and multiple namespaces the same in
TFuncKey
by flattening an array of namespaces into a union of namespace strings. Using this we can use distributive conditional types to handle each namespace individually. See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-typesFor
NormalizeReturn
we use a newDistributiveKeyOf<T>
helper. This finds keys that are available in only one/some of the namespaces, whereas 'keyof T' would only find them if they were in all of the namespaces.We simplify and rework the "with options" overload of TFunction. This no longer allows passing the namespace. That use case is already covered by other overloads before that. This overload was the reason for erroneously suggesting unprefixed keys for not currently active namespaces.
The probably helps with #1887, too.
fixes #1889
Checklist
npm run test