microsoft / microsoft/TypeScript
Type PermissionName for Permission API doesn't contain microphone and camera devices
@sandersn ci sta già lavorando.
Dal 30/8/2024.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔍 Search Terms
microphone, camera, device, permission, state, API, navigator
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
In both files, webworker.generated.d.ts and dom.generated.d.ts in line 9361 and 27992.
The modification would be add two terms in the type PermissionName. 'camera' and 'microphone' to check access in both devices
📃 Motivating Example
const checkForPermission = (type: PermissionName) => {
navigator.permissions
.query({
name: type,
})
.then(permissionStatus => {
// Will be 'granted', 'denied' or 'prompt':
console.log(permissionStatus);
// permissionStatus.state = 'granted'
// Listen for changes to the permission state
permissionStatus.onchange = () => {
console.log(permissionStatus.state);
};
});
};
checkForPermission('microphone');
checkForPermission('camera');
Expected behavior:
'microphone' and 'camera' should be valid types for PermissionName type.
Actual behavior:
'microphone' and 'camera' are not valid types for PermissionName type.
Typescript is showing error:
Argument of type '"microphone"' is not assignable to parameter of type 'PermissionName'.
💻 Use Cases
-
What do you want to use this for?
Check if camera or microphone are enabled/disabled -
What shortcomings exist with current approaches?
To type the promise from navigator.permission in typescript, we have to add a inclusion on type PermissionName like: { PermissionName } & { name: 'camera' | 'microphone' }. -
What workarounds are you using in the meantime?
I'm using it: { PermissionName } & { name: 'camera' | 'microphone' }
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.