Element: [Feature Request] add declaration or interface for locale

Created on 30 Dec 2017  ·  10Comments  ·  Source: ElemeFE/element

Existing Component

Yes

Component Name

locale

Description

compile
import locale from 'element-ui/lib/locale/lang/en';
by typescript with --strict causes following error

ERROR in [at-loader] ./src/main/typescript/static/default/index.ts:1:20 
    TS7016: Could not find a declaration file for module 'element-ui/lib/locale/lang/en'. 'node_modules/element-ui/lib/locale/lang/en.js' implicitly has an 'any' type.
  Try `npm install @types/element-ui/lib/locale/lang/en` if it exists or add a new declaration (.d.ts) file containing `declare module 'element-ui/lib/locale/lang/en';

compile with --noImplicytAny or webpack with NormalModuleReplacementPlugin can workaround the issue, but not ideal.

Vue.js awares typescript and recommending compile options with --strict enabled.
(see "Recommended Configuration" in "TypeScript Support" page)

so, is it possible to have declaration file for locale?

also, having interface for locale(e.g. ElementLocale) and define locale as following

export default en: ElementLocale = {  ... }
export default de: ElementLocale = {  ... }
export default fr: ElementLocale = {  ... }

locale import could be slightly easier
import {en, de, fr} from 'element-ui/locale';

thanks.
//

stale help wanted feature request

Most helpful comment

I think @subaru44k methods is wording around to me.
Add locale.d.ts
image
In main.ts
image

All 10 comments

I have the same problem, too. but I can't resolve it. Do you have any better ideas?

I have

    "strict": true,
    "noImplicitAny": false,

in my tsconfig.json for time being.
too bad typescript compiler doesn't allow us to override compile options per file basis...

of course, declaration file is ultimate solution.
I tried to create declaration file or something but no success...
//

I have the same problem and noImplicitAny is not a best solution... I will try to create declaration module for this...

i want to konw hwo to git it

I also want to know how to solve this problem

Adding locale.d.ts file in your project (for example, 'src/types' directory) may resolve the problem.
(but it's workaround)
Content is following.

declare module 'element-ui/lib/locale/lang/en' {
}

I think @subaru44k methods is wording around to me.
Add locale.d.ts
image
In main.ts
image

using the locale.d.ts under /types and then trying to import brings up a new error in vs code:

Module '\"element-ui/lib/locale/lang/en\"' has no default export.

A different error shows up during compilation:

Could not find a declaration file for module 'element-ui/lib/locale/lang/en

How can I import the locales without using noImplicitAny ?

Edit:

Had to use import * as locale from 'element-ui/lib/locale/lang/en';

Same problem here. There is not a type file for the locales by the looks of it.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings