gatsby-plugin-intl
gatsby-plugin-intl copied to clipboard
Add type declarations
We are using typescript in our project. Can't import methods/components from gatsby-plugin-intl because it doesn't have a type declarations. Can you please add a type declarations?
Here is a quick and dirty workaround for a .d.ts file. However, it is incomplete and does not cover everything, that is exported from index.js:
declare module "gatsby-plugin-intl" {
import * as gatsby from "gatsby";
export class Link<TState> extends gatsby.Link<TState> {}
export const navigate: typeof gatsby.navigate;
export const changeLocale: (language: string, to?: string) => void;
}
Covers everything except deprecated withIntl
:
declare module 'gatsby-plugin-intl' {
import * as gatsby from 'gatsby';
import React from 'react';
export * from 'react-intl';
export class Link<TState> extends gatsby.Link<TState> {}
export const navigate: typeof gatsby.navigate;
export const changeLocale: (language: string, to?: string) => void;
export const IntlContextProvider: React.Provider;
export const IntlContextConsumer: React.Consumer;
}
Makes sense to add this to the project, so we don't need to implement dirty hacks.
With that file definition, I get an error stating that React.Provider and React.Consumer require one type argument, which is the type of the value.
11:37 Generic type 'Consumer' requires 1 type argument(s).
9 | export const changeLocale: (language: string, to?: string) => void;
10 | export const IntlContextProvider: React.Provider;
> 11 | export const IntlContextConsumer: React.Consumer;
| ^
12 | }