question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autocompletion and type-safe with typescript

See original GitHub issue

Just checked next-intl library and amazed that it has support for typescript integration and autocompletion out of the box

https://next-intl-docs.vercel.app/docs/usage/typescript

so that we can have type-safe and autocompletion in our t Function t("home.title")

I’m not sure if next-i18next supports this already or not, because I couldn’t find any step on how to do this in next-i18next issues or description.

Is there some way to do this? or even maybe this case isn’t necessary? Because I think it would be convenient to have this

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
TrebuhDcommented, Aug 13, 2022

This should do the trick (next-i18next.d.ts)

// import the original type declarations
import "react-i18next";

// import all namespaces (for the default language, only)
import type en from "@public/locales/en/common.json";

declare module "react-i18next" {
  // and extend them!
  interface CustomTypeOptions {
    // custom resources type
    resources: {
      common: typeof en;
    };
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

no autocomplete from inferred return types (generics) - YouTrack
Autocomplete doesn't work until user strictly declares type of a variable. IDE fails to infer the correct return-value from "$resource<IArticleResource, ...
Read more >
In typescript, can a generic function return an extended ...
I was trying to add type checking to an const object and also keep the auto completion. The very first ...
Read more >
Building LOOSE AUTOCOMPLETE with TypeScript - YouTube
Comments • 24 ; Dynamic function arguments with GENERICS - Advanced TypeScript. Matt Pocock · 12K views ; Enums considered harmful. Matt Pocock ......
Read more >
Flexible Types that Support Autocomplete with Template ...
In Typescript, when defining a type, it's nice to use a union of literals: 1type Sizes = "sm" | "md" | "lg".
Read more >
mui-ts-generic-autocomplete - CodeSandbox
TemplateReact Typescript; Environmentcreate-react-app. Files. public. src. App.tsx. index.tsx. package.json. tsconfig.json. Dependencies. @material-ui/core.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found