ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
12.04k stars 999 forks source link

bug: #6078

Closed kuklyuk closed 1 year ago

kuklyuk commented 1 year ago

Bug Report

Capacitor Version

@capacitor/core: 4.4.0 @capacitor/cli: 4.4.0 @capacitor/android: 4.4.0 @capacitor/local-notifications@4.1.2

Platform(s)

Android

Current Behavior

Trying to register a notification channel with LocalNotifications plugin. Unable to set "importance" property. According to doc, this property is of a special "Importance" type, but the value must be one of 1 | 2 | 3 | 4 | 5. Trying to set simply {importance : 5} triggers the following compile error:

Argument of type '{ id: string; name: string; description: string; importance: number; lightColor: string; sound: string; vibration: boolean; }' is not assignable to parameter of type 'Channel'. Types of property 'importance' are incompatible. Type 'number' is not assignable to type 'Importance'. E.g. the compilation behavior does not correspond wit the documentation.

The documentation means that the property must be one of the following values: 1 | 2 | 3 | 4 | 5. The native Android platform also accepts this property as an int constant. Evidently the plugin does not provide any special enums or named constants. Ergo: either the compiler must accept a simple integer value, or the documentation must show another proper way to set this property.

Expected Behavior

Normally register a channel.

Code Reproduction

const channel = { id: "tiko_notifications", name: "TiKo", description: "TiKo reminder channel", importance: 5, lightColor: "#FFFFFF", sound: "expiration.wav",
vibration: true
}; await LocalNotifications.createChannel( channel );

Other Technical Details

npm --version output: 8.11.0 node --version output: 16.16.0 Ionic 6.20.1 Windows 11 Pro

Ionitron commented 1 year ago

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks! Ionitron 💙

kuklyuk commented 1 year ago

Reproduction App: https://github.com/kuklyuk/lnchannel.git To reproduce: simply try to compile the Ionic App. The "wrong" code is in the file src/app/app.component.ts function initChannel (Ln 21). Without this function the projects compiles OK.

jcesarmobile commented 1 year ago

You have to tell typescript that the channel object is a LocalNotificationChannel:

const channel: LocalNotificationChannel = {
          id: "tiko_notifications",
          name: "TiKo",
          description: "TiKo reminder channel",
          importance: 5,
          lightColor: "#FFFFFF",
          sound: "expiration.wav",                      
          vibration: true,
};

or that the importance value is of Importance type.

    const importance: Importance = 5;
    const channel = {
                      id: "tiko_notifications",
                      name: "TiKo",
                      description: "TiKo reminder channel",
                      importance: importance,
                      lightColor: "#FFFFFF",
                      sound: "expiration.wav",                      
                      vibration: true                      
                    };
ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.