Skip to content

i18n middleware format function could be typed by message keys #591

@JamesLMilner

Description

@JamesLMilner

Enhancement

The format function in the i18n middleware is currently typed as (key: string, options?: any):

https://github.com/dojo/framework/blob/master/src/core/middleware/i18n.ts#L94

It would be useful to be able to ensure that the key argument was a type of the key of the messages in the bundle to prevent passing invalid key property.

Package Version: 7.0.0-pre

Code

Assume an .nls file as such:

const messages = {
     foosAvailable: '{num} are available'
};

export default { messages };

A widget with this behaviour in the render

const { messages, format } = i18n.localize(bundle);
// Later on
format('barsAvailable', { num: bars.length })}

Expected behavior:

A type error occurs when using a no message bundle key.

Actual behavior:

There is no type error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: i18nInternationalisationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions