Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'platform' is declared but never used

Why I got this warning by tslint?

Package name: io.ionic.starter
[18:37:16]  tslint: s:/IonicProject/VerificheNawi/src/pages/home/home.ts, line: 14
        Property 'platform' is declared but never used.

  L14:    constructor(public navCtrl: NavController, private platform: Platform, public splash: SplashScreen) {
  L15:      platform.ready().then(()  => {

As you can see, L15 use platform... I wonder if there is something I didn't yet understood about injection.

like image 229
Pietro Molina Avatar asked Dec 10 '22 10:12

Pietro Molina


1 Answers

The problem is the line number 14. So try with this:

constructor(platform: Platform, public navCtrl: NavController, public splash: SplashScreen) {

by omitting the private keyword for the platform in the constructor, we're telling Typescript not to create a property for it, in this component.

Why? Since you're using the platform like this: platform.ready... you're not using the property from the component, but the parameter from the constructor.

So as I see it, you could fix that in two ways:

  1. Remove the private keyword next to the platform, in the constructor, in order to not create a property in the component, and just use the platform parameter.
  2. Change platform.ready().then(...) by this.platform.ready().then(..) to use the property from the component (by using the this keyword).
like image 167
sebaferreras Avatar answered Dec 14 '22 23:12

sebaferreras