Skip to content

Commit

Permalink
Rewrite type check compatibility trick after review
Browse files Browse the repository at this point in the history
  • Loading branch information
peaBerberian committed Aug 1, 2024
1 parent 96f4091 commit 6429671
Showing 1 changed file with 13 additions and 51 deletions.
64 changes: 13 additions & 51 deletions src/compat/browser_compatibility_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,57 +317,19 @@ export interface IMediaKeySession extends IEventTarget<MediaKeySessionEventMap>
update(response: BufferSource): Promise<void>;
}

/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-restricted-types */
// @ts-expect-error unused function, just used for compile-time typechecking
function testMediaElement(x: HTMLMediaElement) {
assertCompatibleIMediaElement(x);
}
function assertCompatibleIMediaElement(_x: IMediaElement) {
// Noop
}
// @ts-expect-error unused function, just used for compile-time typechecking
function testMediaSource(x: MediaSource) {
assertCompatibleIMediaSource(x);
}
function assertCompatibleIMediaSource(_x: IMediaSource) {
// Noop
}
// @ts-expect-error unused function, just used for compile-time typechecking
function testSourceBuffer(x: SourceBuffer) {
assertCompatibleISourceBuffer(x);
}
function assertCompatibleISourceBuffer(_x: ISourceBuffer) {
// Noop
}
// @ts-expect-error unused function, just used for compile-time typechecking
function testSourceBufferList(x: SourceBufferList) {
assertCompatibleISourceBufferList(x);
}
function assertCompatibleISourceBufferList(_x: ISourceBufferList) {
// Noop
}
// @ts-expect-error unused function, just used for compile-time typechecking
function testMediaKeySystemAccess(x: MediaKeySystemAccess) {
assertCompatibleIMediaKeySystemAccess(x);
}
function assertCompatibleIMediaKeySystemAccess(_x: IMediaKeySystemAccess) {
// Noop
}
// @ts-expect-error unused function, just used for compile-time typechecking
function testMediaKeys(x: MediaKeys) {
assertCompatibleIMediaKeys(x);
}
function assertCompatibleIMediaKeys(_x: IMediaKeys) {
// Noop
}
// @ts-expect-error unused function, just used for compile-time typechecking
function testMediaKeySession(x: MediaKeySession) {
assertCompatibleIMediaKeySession(x);
}
function assertCompatibleIMediaKeySession(_x: IMediaKeySession) {
// Noop
}
/* eslint-enable @typescript-eslint/no-unused-vars, @typescript-eslint/no-restricted-types */
/* eslint-disable @typescript-eslint/no-restricted-types */
// Trick to ensure our own types are compatible to TypeScript's
function assertTypeCompatibility<T, _U extends T>(): void {
// noop
}
assertTypeCompatibility<IMediaElement, HTMLMediaElement>();
assertTypeCompatibility<IMediaSource, MediaSource>();
assertTypeCompatibility<ISourceBuffer, SourceBuffer>();
assertTypeCompatibility<ISourceBufferList, SourceBufferList>();
assertTypeCompatibility<IMediaKeySystemAccess, MediaKeySystemAccess>();
assertTypeCompatibility<IMediaKeys, MediaKeys>();
assertTypeCompatibility<IMediaKeySession, MediaKeySession>();
/* eslint-enable @typescript-eslint/no-restricted-types */

/**
* AudioTrackList implementation (that TS forgot).
Expand Down

0 comments on commit 6429671

Please sign in to comment.