Repository navigation
Ship TypeScript types - #296
Merged
Merged
Conversation
@types/node-pushnotifications is stuck at 3.1.1: no { id, type } or topic
destinations, no 7.0 result shape, and it pulls in firebase-admin 11.
Bundled types stay in sync with the code and take precedence over @types.
Type tests in test/types run in CI, and check-package compiles a consumer
against the packed tarball with TypeScript 7 and 5.9.
Closes #193
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Web Push errors can be plain errors, so the HTTP fields are optional - String data only type-checks for Web Push destinations - fcm settings need a credential, wns settings need notificationMethod - Reject ambiguous destinations and the removed data.recipients - Accept readonly arrays, array locArgs and the APNs critical sound object - Exact type assertions with expect-type, attw in check-package, and TypeScript 5.5 as the oldest checked version Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The package now ships its own TypeScript types, so
@types/node-pushnotificationsis no longer needed.Why
The DefinitelyTyped package is stuck at 3.1.1. It doesn't know
{ id, type }destinations, FCM topics and conditions, or the 7.0 result shape. It typessend()with a callback as returningvoid, and it pulls in firebase-admin 11. TypeScript prefers a package's owntypesover@types, so the bundled file takes over even where the old package is still installed.What's typed
index.d.tsis hand-written next toindex.jsand usesexport =with a merged namespace, matchingmodule.exports = PNand the static constants.import PN, { FCM } from 'node-pushnotifications'andrequireboth work. Settings, destinations,dataand results are taken from the senders rather than the old types.Settings that can't work are rejected:
fcmneedsserviceAccountKeyorcredential, andwnsneedsnotificationMethod, since passing either replaces the defaults. A stringdataonly type-checks for Web Push destinations, the only service that sends it as is. Ambiguous destinations such as a topic with anidfail to compile, as does thedata.recipientsremoved in 7.0.Results are a union keyed on
method. Checkingr.method === 'fcm'gives aFirebaseErrorwithcode, and'webPush'gives the subscription and an optionalstatusCode(network and option errors don't have one). The README's stale-token example now filters onmethodfirst so it type-checks, and gained a Web Push 404/410 example.datastays open because WNS and ADM pass extra fields through. Known fields are still checked, and the open parts useanyindex signatures so payloads typed as interfaces are accepted. Firebase and node-apn types are imported from those packages. Web Push shapes are defined inline, so there's no@types/web-pushdependency.Checks
npm run test:typescompilestest/types/and runs in CI. It covers the README and docs examples,@ts-expect-errorcases that must fail, and exact type assertions withexpect-type, so an accidentalanyfails the check.check-package.shruns attw on the packed tarball and compiles a consumer against it with TypeScript 7.0 and 5.5, the oldest version supported. 5.5 is needed for the README's narrowing infilter().Closes #193
🤖 Generated with Claude Code