microsoft / microsoft/TypeScript

RTCStatsReport should inherit or extend from Map

Open
#58,995 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Needs More Info
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

⚙ Compilation target

ESNEXT

⚙ Library

No idea why this item is mandatory

Missing / Incorrect Definition

RTCStatsReport is defined as follows:

/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCStatsReport) */
interface RTCStatsReport {
    forEach(callbackfn: (value: any, key: string, parent: RTCStatsReport) => void, thisArg?: any): void;
}

As per documentation, RTCStatsReport is a Map-like object so it should include methods such as values(), entries() and members such as size. Note that it must NOT include delete(), clear() or set() since it's read-only (see doc links at the bottom).

However RTCStatsReport TypeScript definition only exposes forEach().

Sample Code
const pc = new RTCPeerConnection();

pc.createDataChannel('foo', { negotiated: true, id: 123, ordered: true });

const stats = await pc.getStats();

console.log('--- num stats:', stats.size);

for (const [id, stat] of stats) {
	console.log('--- stat:', stat);
	console.log('--- stats.get(id):', stats.get(id));
}

Produces:

--- num stats: 2
--- stat: {id: 'D37', timestamp: 1719306842612.802, type: 'data-channel', bytesReceived: 0, bytesSent: 0, …}
--- stats.get(id): {id: 'D37', timestamp: 1719306842612.802, type: 'data-channel', bytesReceived: 0, bytesSent: 0, …}
--- stat: {id: 'P', timestamp: 1719306842612.802, type: 'peer-connection', dataChannelsClosed: 0, dataChannelsOpened: 0}
--- stats.get(id): {id: 'P', timestamp: 1719306842612.802, type: 'peer-connection', dataChannelsClosed: 0, dataChannelsOpened: 0}
Documentation Link

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.

Research direction

Start from the RTCStatsReport interface shown in the issue and compare it with the linked MDN map-like API documentation. Confirm the read-only members and iteration behavior represented by the sample, while excluding delete(), clear(), and set(); done means the TypeScript definition exposes the documented behavior accurately.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
web-dev
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.