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

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

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

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

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

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

@ -20,7 +20,7 @@ export function useFlyout(options: UseFlyoutOptions) {
listeners++ listeners++
const unwatch = watch(focusedElement, (el) => { 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 focus.value = true
options.onFocus?.() options.onFocus?.()
} else { } else {

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

@ -139,7 +139,7 @@ export async function bundle(
} }
// build <script client> bundle // build <script client> bundle
if (Object.keys(clientJSMap).length) { 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[] = [] importStack: string[] = []
): boolean { ): boolean {
if (cache.has(id)) { if (cache.has(id)) {
return cache.get(id) as boolean return !!cache.get(id)
} }
if (importStack.includes(id)) { if (importStack.includes(id)) {
// circular deps! // circular deps!

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

Loading…
Cancel
Save