0

I’m using babel-plugin-react-intl-auto and TypeScript.

This package has defined typings in lib/types.d.ts (It is in lib when installed using npm). These override typings of another package.

import { FormattedMessage } from 'react-intl'

declare module 'react-intl' {
  interface ExtractableMessage {
    [key: string]: string
  }

  export function defineMessages<T extends ExtractableMessage>(
    messages: T
  ): { [K in keyof T]: FormattedMessage.MessageDescriptor }
}

They have specified this in package.json

{
  // ...
  "types": "lib/types.d.ts",
  // ...
}

This all seems fine. However, When I use this package, TypeScript complains about the function signature of defineMessages.

If I copy those typings into my own index.d.ts, it just works as expected.

For completness sake, this is my tsconfig.json:

{
  "compilerOptions": {
    "noEmit": true,
    "noImplicitAny": true,
    "esModuleInterop": true,
    "jsx": "react",
    "lib": ["es5", "es6", "dom"]
  }
}

Why won’t TypeScript use these typings?

1 Answer 1

1

This is most likely because TypeScript has no context as to which version of defineMessages to use.
TypeScript supports merging declarations which also gets applied when importing modules.

Importing babel-plugin-react-intl-auto alongside react-intl should merge these definitions, allowing TypeScript to understand both syntaxes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.