Typescript payload not inferred in "new i18n"
See original GitHub issueUnless I’m missing something, new i18n(config)
does not infer the type of Params
from config
so @sveltekit-i18n/parser-default
needs to be imported just to get the Parser
type to declare it explicitly.
For translations.ts
I am forced to do this so that my type checking doesn’t return an error:
import i18n from 'sveltekit-i18n';
import type { Config } from 'sveltekit-i18n';
import type { Parser } from '@sveltekit-i18n/parser-default';
export const defaultLocale = 'en';
export interface Payload extends Parser.PayloadDefault {
placeholder?: string;
}
const config: Config<Payload> = {
...
};
export const { t, locale, locales, loading, loadTranslations, translations } = new i18n<
Parser.Params<Payload>
>(config);
If I don’t include <Parser.Params<Payload>>
, I get an error that placeholder
doesn’t exist when passing it to a $t(...)
.
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
Why am I getting "Type instantiation is excessively deep and ...
The AllModuleActions<M> type is recursive in a way that the compiler cannot handle very well. You are indexing arbitrarily deep into an ...
Read more >Exact Types · Issue #12936 · microsoft/TypeScript - GitHub
Primary use-case is when you're creating a new type from ... Interface Inferred from Property Not Rejecting Invalid Properties #50732.
Read more >Using with TypeScript - Ajv JSON schema validator
Note that it's currently not possible for JTDDataType to know whether the compiler is inferring timestamps as strings or Dates, and so it...
Read more >Typescript and Redux. My tips. - DEV Community
Each state in Redux should be immutable. Immutable object cannot be modified after it is created. If you forget this rule, your component...
Read more >TypeScript with Options API - Vue.js
Typing Component Emits #. We can declare the expected payload type for an emitted event using the object syntax of the emits option....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It works here, when
@sveltekit-i18n/base
and@sveltekit-i18n/parser-default
are used separately, but it does not work undersveltekit-i18n
, so you are 100% right aboutsveltekit-i18n
declaration…I am not an expert in typescript but for example instead of:
This works for me:
That way it just needs
const config: Config<{param?: number}>
and nothing else.