gatsby-plugin-intl icon indicating copy to clipboard operation
gatsby-plugin-intl copied to clipboard

Add type declarations

Open chertkovalex opened this issue 5 years ago • 3 comments

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?

chertkovalex avatar Jul 31 '19 14:07 chertkovalex

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;
}

joernb avatar Aug 06 '19 15:08 joernb

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.

artemtam avatar Dec 27 '19 11:12 artemtam

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 | }

BertrandFritsch avatar May 25 '20 15:05 BertrandFritsch