fix(types): expose enableSelector on InitOptions#2431
Conversation
`enableSelector` is a runtime option — `i18next.js` reads
`opts?.enableSelector === 'strict'` inside `keysFromSelector` and applies
the namespace-prefix rewrite accordingly — but it isn't declared on
`InitOptions`. So `i18n.init({ enableSelector: 'strict' })` fails to
typecheck with:
Object literal may only specify known properties, and
'enableSelector' does not exist in type 'InitOptions<unknown>'.
`CustomTypeOptions['enableSelector']` exists for the type-level selector
machinery, but that only configures the compile-time shape. The runtime
value still has to be passed at init() time, and the matching
InitOptions field was missing.
Adds `enableSelector` to InitOptions alongside `keySeparator` and
`nsSeparator`, and adds an i18nInstance.test.ts case covering each
accepted value (false / true / 'optimize' / 'strict').
|
Shipped in i18next 26.2.0. Thanks @Faithfinder! |
|
@adrai @Faithfinder do you know whether it'd be straightforward to expand this type coverage (I suppose for all |
|
@jayaddison good call — turned out to be straightforward. Just shipped it in jquery-i18next@1.3.0 — and hey, 9 years between releases, good to know jquery-i18next still has users! 😄 The package now ships its own TypeScript definitions covering all of jquery-i18next's |
|
That's super impressive - thank you @adrai! I'll update |
|
@adrai that upgrade of |
Problem
enableSelectoris a runtime option —i18next.jsreadsopts?.enableSelector === 'strict'insidekeysFromSelectorand applies the namespace-prefix rewrite accordingly — but it isn't declared onInitOptions. As a result,i18n.init({ enableSelector: 'strict' })fails to typecheck:CustomTypeOptions['enableSelector']exists (used for the type-level selector machinery int.d.ts), but that only configures the compile-time shape. Users still have to passenableSelectorat runtime to actually get strict-mode resolution, and the matchingInitOptionsfield is missing.Today every project enabling the selector API needs a module augmentation:
Fix
Adds the runtime-side option to
InitOptions, slotted next to the other selector-resolution knobs (keySeparator/nsSeparator).Includes a
test/typescript/misc/i18nInstance.test.tscase covering each accepted value: