Nativescript: "globals" changes in v3.0.0 ?

Created on 18 May 2017  路  9Comments  路  Source: NativeScript/NativeScript

Hi,

I have a user that reports he cannot use global.L() anymore since the update - https://github.com/rborn/nativescript-i18n/issues/57
I didn't change any behaviour related to the global scope in the plugin when I updated it for 3.0.0.

Could anyone give us some ideas?
Thank you.

PS (I'm not good with typescript 馃槥)

question

Most helpful comment

Or even better create a lib.d.ts file like

declare namespace NodeJS {
    interface Global {
        process: any; // tslint:disable-line
    }
}

we used that for using redux

All 9 comments

Hi @rborn,
Thank you for writing us this issue.
From NativeScirpt 3.0 global module is typified. In this case, such methods like L() , which do not exist in global will break the typescript compilation.
In your scenario, you could cast global to any, which will allow you to use the needed methods in NativeScript Typescript application.
For example:

declare var global:any;

Or even better create a lib.d.ts file like

declare namespace NodeJS {
    interface Global {
        process: any; // tslint:disable-line
    }
}

we used that for using redux

@Buuhuu @tsonevn thank you, should I do this in the plugin or each project needs this?

This extends the typing of the current project (similar to how the typescript typing libs work) so it has to be done in each project. I usually put that file in the root of my project as I might have to add even more there.

@Buuhuu thank you

@Buuhuu
could u show more detail?
i created lib.d.ts with same content as u provided in my project(based on typescript), my code still not working.

i have some code like following based on nativescript 2.5.*

global.xxx = function()
{
    .........................
} 

the error message is: app/app.ts(450,8): error TS2339: Property 'xxx' does not exist on type 'Global'.

@Buuhuu same question as @shyandsy. How to setup the lib.d.ts properly to avoid declaring global as any in every file. Thanks in advance.

Thanks @Buuhuu
I was looking to overcome process: is undefined issue when implementing Angular + Redux with nativescript.
The following steps resolved the issue..

  1. As @Buuhuu stated - created a lib.d.ts in my root folder with below contents - This wasn't enough to resolve the issue, you will need to set the global member process as mentioned in step 2
declare namespace NodeJS {
    interface Global {
        process: {
            env: any
        }; // tslint:disable-line
    }
}
  1. In my main.ts file added the below line - this will make redux.js find global.process member.
global.process = {
    env: {}
};

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings