aurelia / i18n

A plugin that provides i18n support.
MIT License
93 stars 70 forks source link

fix(i18n): Fix typings issue for i18next import #297

Closed rmja closed 5 years ago

rmja commented 5 years ago

The current import syntax produces a .d.ts file that requires the consuming app to compile with allowSyntheticDefaultImports: true.

zewa666 commented 5 years ago

Hi @rmja.

We sadly can't add this import. We had it before but it behaves super strange with JS consumers. The trouble comes from the default export being used by the backing library i18next. So as said as it is we really can't do too much about this one.

rmja commented 5 years ago

Ahh crap. Would it then be possible to rewrite the .d.ts in the dist folder (https://github.com/aurelia/i18n/blob/master/dist/aurelia-i18n.d.ts#L1) in the build script. I guess this file is only consumed by Typescript users.

zewa666 commented 5 years ago

Not sure if that alone really helps. Could you give it a try locally and see whether thats enough? Weve got even a build step in place which just modifies the d.ts the other way around

rmja commented 5 years ago

It seems to work.

If I have:

.plugin(PLATFORM.moduleName("aurelia-i18n"), (instance: I18N) => {
            instance.i18next.use(Backend); // <-- Typescript compile error here

            return instance.setup({
                backend: {
                    loadPath: 'locales/{{lng}}/{{ns}}.json'
                },
                lng: 'da'
            });
        })

Then I get a Typescript compile error on the marked line. The compile error goes away if I manually set import * as i18next from 'i18next'; in node_modules/aurelia-i18n/dist/aurelia-i18n.d.ts in my project.

zewa666 commented 5 years ago

btw. what version of i18next was installed for you @rmja. It might be that the typings issue got fixed with one of their latest releases. There is another currently active PR for I18N which addresses the update from v 11 to 14 so maybe in between there is a change affecting your's as well.

Anyways can I ask you to modify your PR to revert the change for i18n.ts and instead modify this section here, which is responsible for the d.ts generation.

rmja commented 5 years ago

Closing in favor of https://github.com/aurelia/i18n/pull/299