mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: return type of $
This commit is contained in:
parent
b877c258cc
commit
e4e2389868
3 changed files with 12 additions and 6 deletions
|
|
@ -2,7 +2,7 @@ import * as React from 'react'
|
|||
import * as ReactDOM from 'react-dom'
|
||||
|
||||
type Props = {
|
||||
into: HTMLElement
|
||||
into: Element
|
||||
}
|
||||
|
||||
class Portal extends React.PureComponent<Props> {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ export type ConnectorState = {
|
|||
compressSingletonFolder?: boolean
|
||||
copyFileButton?: boolean
|
||||
copySnippetButton?: boolean
|
||||
logoContainerElement: HTMLElement | null
|
||||
logoContainerElement: Element | null
|
||||
|
||||
init: () => void
|
||||
onPJAXEnd: () => void
|
||||
|
|
|
|||
|
|
@ -28,11 +28,17 @@ function setBodyIndent(shouldShowGitako: boolean) {
|
|||
}
|
||||
}
|
||||
|
||||
function $<R1 = never, R2 = never>(
|
||||
function $<E extends (element: Element) => any, O extends () => any>(
|
||||
selector: string,
|
||||
existCallback?: (element: Element) => R1,
|
||||
otherwise?: () => R2,
|
||||
): R1 | R2 | Element {
|
||||
existCallback?: E,
|
||||
otherwise?: O,
|
||||
): E extends never
|
||||
? O extends never
|
||||
? (Element | null)
|
||||
: ReturnType<O> | null
|
||||
: O extends never
|
||||
? (ReturnType<E> | null)
|
||||
: ReturnType<O> | ReturnType<E> {
|
||||
const element = document.querySelector(selector)
|
||||
if (element) {
|
||||
return existCallback ? existCallback(element) : element
|
||||
|
|
|
|||
Loading…
Reference in a new issue