jpush / jpush/jpush-react-native

应该定义声明文件中泛型的类型

Open
#779 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.4k
Forks
348
PR merge metrics
No merged PRs in 30d

Description

你的运行环境

  • 插件版本: 2.8.0
  • react-native 版本:0.62

期望效果

定义声明文件中泛型的类型。以便更好的书写TypeScript。

实际效果

原来:

static addNotificationListener(
    callback: Callback<{
      /**
       *  messageID:唯一标识通知消息的 ID
       */
      messageID: string;
      /**
       *  title:对应 Portal 推送通知界面上的“通知标题”字段
       */
      title: string;
      /**
       *  content:对应 Portal 推送通知界面上的“通知内容”字段
       */
      content: string;
      /**
       *  badge:对应 Portal 推送通知界面上的可选设置里面的“badge”字段 (ios only)
       */
      badge: string;
      /**
       *  ring:对应 Portal 推送通知界面上的可选设置里面的“sound”字段 (ios only)
       */
      ring: string;
      /**
       *  extras:对应 Portal 推送消息界面上的“可选设置”里的附加字段
       */
      extras: Extra;
      /**
       *  notificationEventType:分为notificationArrived和notificationOpened两种
       */
      notificationEventType: "notificationArrived" | "notificationOpened";
    }>
  ): void;

期望修改为:

export interface CustomType {
  /**
   *  messageID:唯一标识通知消息的 ID
   */
  messageID: string;
  /**
   *  title:对应 Portal 推送通知界面上的“通知标题”字段
   */
  title: string;
  /**
   *  content:对应 Portal 推送通知界面上的“通知内容”字段
   */
  content: string;
  /**
   *  badge:对应 Portal 推送通知界面上的可选设置里面的“badge”字段 (ios only)
   */
  badge: string;
  /**
   *  ring:对应 Portal 推送通知界面上的可选设置里面的“sound”字段 (ios only)
   */
  ring: string;
  /**
   *  extras:对应 Portal 推送消息界面上的“可选设置”里的附加字段
   */
  extras: Extra;
  /**
   *  notificationEventType:分为notificationArrived和notificationOpened两种
   */
  notificationEventType: "notificationArrived" | "notificationOpened";
}
export default class JPush {
// ...
  static addNotificationListener(
    callback: Callback<CustomType>
  ): void;
}

这样使用者可以更好的书写ts

private notificationListener: Callback<CustomType>
this.notificationListener = result => {
  // result 即为 CustomType 类型
}

重现步骤

Debug logs

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the TypeScript declaration file containing JPush.addNotificationListener and its Callback type. Review the existing inline notification payload type, then expose the requested named type and use it in the listener signature. Done means consumers can reference the payload type when writing TypeScript callbacks.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
mobile
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.