alibaba / react-intl-universal

Internationalize React apps. Not only for Component but also for Vanilla JS.
1.33k stars 153 forks source link

intl type hints #226

Closed dvlin-dev closed 11 months ago

dvlin-dev commented 11 months ago

The api I often use is intl.get, which is a great api. But the problem is, when I type intl, there is no automatic prompt to import react-intl-universal.

image

To solve this problem, I used a code snippet, but it was not a good experience. I hope to solve this problem from the API level.

"import intl": {
    "prefix": "ii",
    "body": [
        "import intl from 'react-intl-universal';"
    ],
},

I modified index.d.ts.

declare module "react-intl-universal" {

+  const intl: {
+      determineLocale: typeof determineLocale;
+      formatHTMLMessage: typeof formatHTMLMessage;
+      formatMessage: typeof formatMessage;
+      get: typeof get;
+      getHTML: typeof getHTML;
+      getInitOptions: typeof getInitOptions;
+      init: typeof init;
+      load: typeof load;
+    };
+
+  export default intl;

}

it solved the problem of code suggestions.

image