You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Resolve typescript types to support variables with literal types and union types of literal types being passed to the translation function as keys.
Motivation
i18next-parser has some known caveats.
The need for the workaround is disappointing, as the purpose of the tool is to remove such manual maintenance, especially when the required information is available through typescript.
Example
The following keys a and b should be extracted from the following code:
leta: 'a'|'b';a=Math.random()>.5 ? 'a' : 'b';i18n.t(a);
Implementation Notes
I implemented a proof of concept at mspiess/i18next-parser-ts.
Using type information requires access to the typeChecker which precludes the use of ts.createProgram instead of ts.createSourceFile. createProgram admits a list of root file paths and walks the project from there.
Using it would require replacing the current vfs node stream architecture, which seems like a lot of work which would possibly incur some breaking changes, so I'd appreciate advice on the feasibility of such a major undertaking.
Maybe it's also possible to assemble a typeChecker without using createProgram. I don't know the typescript internals well enough to tell.
The text was updated successfully, but these errors were encountered:
🚀 Feature Proposal
Resolve typescript types to support variables with literal types and union types of literal types being passed to the translation function as keys.
Motivation
i18next-parser has some known caveats.
The need for the workaround is disappointing, as the purpose of the tool is to remove such manual maintenance, especially when the required information is available through typescript.
Example
The following keys
a
andb
should be extracted from the following code:Implementation Notes
I implemented a proof of concept at mspiess/i18next-parser-ts.
Using type information requires access to the
typeChecker
which precludes the use ofts.createProgram
instead ofts.createSourceFile
.createProgram
admits a list of root file paths and walks the project from there.Using it would require replacing the current
vfs
node stream architecture, which seems like a lot of work which would possibly incur some breaking changes, so I'd appreciate advice on the feasibility of such a major undertaking.Maybe it's also possible to assemble a
typeChecker
without usingcreateProgram
. I don't know the typescript internals well enough to tell.The text was updated successfully, but these errors were encountered: