refactor: remove type casts

pull/1136/head
Divyansh Singh 3 years ago
parent fdb42cff3f
commit 4e4dd55dc2

@ -3,7 +3,7 @@
"version": "1.0.0-alpha.4",
"description": "Vite & Vue powered static site generator",
"type": "module",
"packageManager": "pnpm@7.4.1",
"packageManager": "pnpm@7.5.0",
"main": "dist/node/index.js",
"types": "types/index.d.ts",
"exports": {

@ -49,7 +49,7 @@ export function usePrefetch() {
return
}
const rIC = (window as any).requestIdleCallback || setTimeout
const rIC = window.requestIdleCallback || setTimeout
let observer: IntersectionObserver | null = null
const observeLinks = () => {
@ -73,8 +73,8 @@ export function usePrefetch() {
})
rIC(() => {
document.querySelectorAll('#app a').forEach((link) => {
const { target, hostname, pathname } = link as HTMLAnchorElement
document.querySelectorAll<HTMLAnchorElement>('#app a').forEach((link) => {
const { target, hostname, pathname } = link
const extMatch = pathname.match(/\.\w+$/)
if (extMatch && extMatch[0] !== '.html') {
return

@ -64,7 +64,7 @@ export function createRouter(
if (latestPendingPath === pendingPath) {
latestPendingPath = null
const { default: comp, __pageData } = page as PageModule
const { default: comp, __pageData } = page
if (!comp) {
throw new Error(`Invalid route component: ${comp}`)
}
@ -82,7 +82,7 @@ export function createRouter(
try {
target = document.querySelector(
decodeURIComponent(targetLoc.hash)
) as HTMLElement
)
} catch (e) {
console.warn(e)
}
@ -190,7 +190,7 @@ export function useRoute(): Route {
}
function scrollTo(el: HTMLElement, hash: string, smooth = false) {
let target: Element | null = null
let target: HTMLElement | null = null
try {
target = el.classList.contains('header-anchor')
@ -207,12 +207,12 @@ function scrollTo(el: HTMLElement, hash: string, smooth = false) {
document.querySelector(offset)!.getBoundingClientRect().bottom + 24
}
const targetPadding = parseInt(
window.getComputedStyle(target as HTMLElement).paddingTop,
window.getComputedStyle(target).paddingTop,
10
)
const targetTop =
window.scrollY +
(target as HTMLElement).getBoundingClientRect().top -
target.getBoundingClientRect().top -
offset +
targetPadding
// only smooth scroll if distance is smaller than screen height.

@ -64,7 +64,7 @@ function initialize(userOptions: DefaultTheme.AlgoliaSearchOptions) {
// @ts-ignore
hitComponent({ hit, children }) {
const relativeHit = hit.url.startsWith('http')
? getRelativePath(hit.url as string)
? getRelativePath(hit.url)
: hit.url
return {

@ -22,7 +22,7 @@ const resolvedHeaders = computed(() => {
function handleClick({ target: el }: Event) {
const id = '#' + (el as HTMLAnchorElement).href!.split('#')[1]
const heading = document.querySelector(id) as HTMLAnchorElement
const heading = document.querySelector<HTMLAnchorElement>(id)
heading?.focus()
}
</script>

@ -8,9 +8,9 @@ const backToTop = ref()
watch(() => route.path, () => backToTop.value.focus())
function focusOnTargetAnchor({ target }: Event) {
const el = document.querySelector(
(target as HTMLAnchorElement).hash!
) as HTMLAnchorElement
const el = document.querySelector<HTMLAnchorElement>(
(target as HTMLAnchorElement).hash
)
if (el) {
const removeTabIndex = () => {

@ -20,7 +20,7 @@ export function useFlyout(options: UseFlyoutOptions) {
listeners++
const unwatch = watch(focusedElement, (el) => {
if (el === options.el.value || options.el.value?.contains(el as Node)) {
if (el === options.el.value || options.el.value?.contains(el!)) {
focus.value = true
options.onFocus?.()
} else {

@ -135,7 +135,7 @@ export function useActiveAnchor(
if (hash !== null) {
prevActiveLink = container.value.querySelector(
`a[href="${decodeURIComponent(hash)}"]`
) as HTMLAnchorElement
)
}
const activeLink = prevActiveLink

@ -139,7 +139,7 @@ export async function bundle(
}
// build <script client> bundle
if (Object.keys(clientJSMap).length) {
clientResult = (await buildMPAClient(clientJSMap, config)) as RollupOutput
clientResult = await buildMPAClient(clientJSMap, config)
}
}
@ -168,7 +168,7 @@ function staticImportedByEntry(
importStack: string[] = []
): boolean {
if (cache.has(id)) {
return cache.get(id) as boolean
return !!cache.get(id)
}
if (importStack.includes(id)) {
// circular deps!

@ -190,7 +190,7 @@ async function resolveUserConfig(
}
const userConfig: RawConfigExports = configPath
? ((
? (
await loadConfigFromFile(
{
command,
@ -199,7 +199,7 @@ async function resolveUserConfig(
configPath,
root
)
)?.config as any)
)?.config!
: {}
if (configPath) {

Loading…
Cancel
Save