Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript: allow defineMessages(... as const) syntax #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

langpavel
Copy link

@langpavel langpavel commented Nov 22, 2019

This PR fixes edge case with as const typescript type modifier like this:

import { defineMessages } from 'react-intl.macro';

const msg = defineMessages({
    name: { id: 'common.name', defaultMessage: 'Name' },
    surname: { id: 'common.surname', defaultMessage: 'Surname' },
} as const);

export default messages;

This is very useful in IDE, you can see id and defaultMessage by hovering prop:
image

BTW I'm using this type definitions, I will add enhanced .d.ts to new PR

declare module 'react-intl.macro' {
    interface MessageDescriptor {
        readonly id: string;
        readonly defaultMessage: string;
        readonly description?: string;
    }

    interface Messages {
        readonly [K: string]: MessageDescriptor;
    }

    export function defineMessages<T extends Messages>(messages: T): T;
}

@codecov
Copy link

codecov bot commented Nov 22, 2019

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.93%. Comparing base (f528cc9) to head (f708a2b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #104      +/-   ##
==========================================
+ Coverage   91.80%   91.93%   +0.13%     
==========================================
  Files           8        8              
  Lines          61       62       +1     
  Branches       10       11       +1     
==========================================
+ Hits           56       57       +1     
  Misses          5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@langpavel
Copy link
Author

langpavel commented Dec 25, 2019

@evenchange4 Please, look at this. It will be really helpful to me. I don't want publish new fork.
Thanks!

@langpavel
Copy link
Author

@evenchange4 please, can you merge?

@langpavel
Copy link
Author

@evenchange4 Can you review this, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant