Home > Software design >  capacitor v3 status-bar gives this error: Type 'SplashScreenPlugin' is not assignable to t
capacitor v3 status-bar gives this error: Type 'SplashScreenPlugin' is not assignable to t

Time:06-20

I am running ionic 6 with capacitor 3. I installed capacitor status-bar and splash screen like this:

npm install @capacitor/status-bar --save
npm install @capacitor/splash-screen --save

npx cap sync

then import then like this:

import { SplashScreen } from '@capacitor/splash-screen';
import { StatusBar, Style } from '@capacitor/status-bar';

followed by:

@NgModule({
  ..........
..........
 providers: [ StatusBar,
              SplashScreen,
             .......
             ]

vscode flags both the StatusBar and the SplashScreen the following error:

Type 'StatusBarPlugin' is not assignable to type 'Provider'.
Type 'SplashScreenPlugin' is not assignable to type 'Provider'.

I also tried switching back to using @ionic-native/splash-screen/ngx' and @ionic-native/status-bar/ngx' and even though this cleared the provider error I got a warning from ivy that these plugins need updating.

can anyone shed some light on why the this error is occurring?

CodePudding user response:

You don't have to register the Plugins as providers. Just use them in your service/components/etc.:

import { Component } from '@angular/core';
import { Badge } from '@robingenz/capacitor-badge';

@Component({
  selector: 'app-badge',
  templateUrl: './badge.page.html',
  styleUrls: ['./badge.page.scss'],
})
export class BadgePage {
  constructor() {}

  public async getBadgeCount(): Promise<number> {
    const result = await Badge.get();
    return result.count;
  }
}
  • Related