Last active
June 3, 2021 18:20
-
-
Save jacksteamdev/8bc05b1257b471f2533bb76b4d58f306 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type WithTabWithId<Type> = Required< | |
{ | |
[Property in keyof Type]: Type[Property] extends { id?: number } | |
? Type[Property] & { id: number } | |
: Type[Property] | |
} | |
> | |
const isWithTabWithId = <T>(args: T): args is WithTabWithId<T> => { | |
if (!Array.isArray(args)) return false | |
const tab = args.find( | |
(x) => | |
x !== null && | |
typeof x === 'object' && | |
'windowId' in x && | |
'pinned' in x && | |
'active' in x, | |
) as Tabs.Tab | undefined | |
if (isUndefined(tab)) { | |
console.warn('tab is undefined') | |
return false | |
} else if (isTabWithId(tab)) { | |
console.warn('tab.id is undefined') | |
return false | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment