content: Missing Event type when trying to subscribe to 'ionBackButton' with React.

Open
#4,261 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Open the hardware back button documentation at the URL in the issue and review the React subscription example. Reproduce the TypeScript error with the documented code, then update the example or its explanation so the documented approach handles the event detail without an unsafe cast; done means the example type-checks for React users.

Written by the indexing model from the issue text.

Description

content
URL

https://ionicframework.com/docs/developing/hardware-back-button

Issue Description

When trying to subscribe to 'ionBackButton' the way it is written on the docs, the compiler complains about the property detail with the message: "Property 'detail' does not exist on type 'Event'.ts(2339)".

The current solution is to cast the event parameter to any. Other solutions have been tried, like casting to BackButtonEvent from @ionic/react or @ionic/core.

Image below is how I found the current solution on the Ionic discord:
Image

npm ls:

├── @capacitor-community/admob@7.0.3
├── @capacitor-community/keep-awake@7.1.0
├── @capacitor/android@7.4.2
├── @capacitor/app@7.0.1
├── @capacitor/assets@3.0.5
├── @capacitor/browser@7.0.2
├── @capacitor/cli@7.4.2
├── @capacitor/core@7.4.2
├── @capacitor/device@7.0.2
├── @capacitor/haptics@7.0.1
├── @capacitor/ios@7.4.2
├── @capacitor/keyboard@7.0.1
├── @capacitor/status-bar@7.0.1
├── @ionic/core@8.7.3
├── @ionic/react-router@8.7.1
├── @ionic/react@8.7.1
├── @testing-library/dom@10.4.1
├── @testing-library/jest-dom@5.17.0
├── @testing-library/react@16.3.0
├── @testing-library/user-event@14.6.1
├── @types/react-dom@19.0.4
├── @types/react-router-dom@5.3.3
├── @types/react-router@5.1.20
├── @types/react@19.0.10
├── @vitejs/plugin-legacy@7.2.1
├── @vitejs/plugin-react@4.7.0
├── cypress@13.17.0
├── eslint-plugin-react-hooks@5.2.0
├── eslint-plugin-react-refresh@0.4.20
├── eslint-plugin-react@7.37.5
├── eslint@9.32.0
├── globals@15.15.0
├── ionicons@7.4.0
├── jsdom@22.1.0
├── react-dom@19.0.0
├── react-router-dom@5.3.4
├── react-router@5.3.4
├── react@19.0.0
├── terser@5.43.1
├── typescript-eslint@8.38.0
├── typescript@5.8.3
├── vite@7.1.1
└── vitest@3.2.4
Dominant language
MDX
Stars
621
Forks
3.2k
Avg merge
1d 2h
Merged PRs (30d)
86

Contributor guide

Open the contributing guide

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.

More from ionic-team/ionic-docs

All issues in ionic-team/ionic-docs

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.