mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-18 19:01:20 -08:00
refactor(vast): [PKG-VAST-04] retain published types and add accurate runtime declarations
This commit is contained in:
1 parent
c162d2b3b3
commit
e5c73fa620
34 files changed
+7819
-1495
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import type Artplayer from 'artplayer'
|
||||
import vast from 'artplayer-plugin-vast'
|
||||
|
||||
type OriginalCallback = (params: {
|
||||
art: Artplayer
|
||||
id: string
|
||||
ima: any
|
||||
imaPlayer: any
|
||||
$container: HTMLDivElement
|
||||
playUrl: (url: string) => void
|
||||
playRes: (response: string) => void
|
||||
}) => void
|
||||
type OriginalResult = { name: 'artplayerPluginVast' }
|
||||
type OriginalFactory = (option: OriginalCallback) => (art: Artplayer) => OriginalResult
|
||||
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false
|
||||
type Assert<T extends true> = T
|
||||
type FactoryCheck = Assert<Equal<typeof vast, OriginalFactory>>
|
||||
type ParameterCheck = Assert<Equal<Parameters<typeof vast>, [option: OriginalCallback]>>
|
||||
type ResultCheck = Assert<Equal<ReturnType<ReturnType<typeof vast>>, OriginalResult>>
|
||||
|
||||
const replacement: typeof vast = (_option) => (_art) => ({ name: 'artplayerPluginVast' })
|
||||
const reverse: OriginalFactory = vast
|
||||
vast(({ art, id, imaPlayer, $container, playUrl, playRes }) => {
|
||||
const identifier: string = id
|
||||
const element: HTMLDivElement = $container
|
||||
imaPlayer.addEventListener('AdStarted', () => {})
|
||||
const url: void = playUrl('/ad.xml')
|
||||
const response: void = playRes('<VAST/>')
|
||||
void [art, identifier, element, url, response]
|
||||
})
|
||||
export type { FactoryCheck, ParameterCheck, ResultCheck }
|
||||
void [replacement, reverse]
|
||||
Reference in new issue
Block a user