Skip to content

Commit 11af513

Browse files
committed
Convert all Vue files to TypeScript
1 parent b3b5bb2 commit 11af513

File tree

7 files changed

+53
-33
lines changed

7 files changed

+53
-33
lines changed

src/App.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<script setup>
1+
<script setup lang="ts">
22
import { ref, onMounted, computed } from "vue"
33
44
import AssistanceModal from "./components/AssistanceModal.vue"
55
import TroubleshooterStep from "./components/TroubleshooterStep.vue"
6-
import { getSteps, generateReport } from "./troubleshooter"
6+
import { getSteps, generateReport, type Option } from "./troubleshooter"
77
8-
const sleep = (m) => new Promise((r) => setTimeout(r, m))
8+
const sleep = (m: number) => new Promise((r) => setTimeout(r, m))
99
1010
const reportCopied = ref(false)
1111
const hash = ref("")
@@ -24,7 +24,7 @@ const needsAssistance = computed(() => {
2424
2525
const report = computed(() => generateReport(steps.value))
2626
27-
function choose(option) {
27+
function choose(option: Option) {
2828
document.location.assign(option.hash)
2929
window.plausible("ArduinoJson Troubleshooter", {
3030
props: {

src/components/AssistanceModal.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script setup>
1+
<script setup lang="ts">
22
import { useTemplateRef } from "vue"
33
44
const { report } = defineProps({
@@ -8,12 +8,13 @@ const { report } = defineProps({
88
},
99
})
1010
11-
const formRef = useTemplateRef("issueForm")
11+
const formRef = useTemplateRef<HTMLFormElement>("issueForm")
12+
const modalRef = useTemplateRef<HTMLDivElement>("modal")
1213
1314
function createIssue() {
14-
const formData = new FormData(formRef.value)
15+
const formData = new FormData(formRef.value!)
1516
16-
const title = formData.get("title")
17+
const title = formData.get("title") as string
1718
let body = ""
1819
1920
const description = formData.get("description")
@@ -48,12 +49,12 @@ function createIssue() {
4849
console.log("URL", url)
4950
window.open(url, "_blank")
5051
51-
bootstrap.Modal.getInstance(this.$el).hide()
52+
bootstrap.Modal.getInstance(modalRef.value!).hide()
5253
}
5354
</script>
5455

5556
<template>
56-
<div class="modal fade">
57+
<div class="modal fade" ref="modal">
5758
<div class="modal-dialog modal-dialog-scrollable modal-lg">
5859
<form class="modal-content" ref="issueForm" @submit.prevent="createIssue">
5960
<div class="modal-header bg-primary text-white">

src/components/TroubleshooterStep.vue

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1-
<script setup>
1+
<script setup lang="ts">
22
import { inject, onMounted, useTemplateRef } from "vue"
33
44
import TroubleshooterStepOption from "./TroubleshooterStepOption.vue"
5+
import type { Option, Step } from "@/troubleshooter"
56
6-
const debug = inject("debug")
7+
const debug = inject<boolean>("debug")
78
8-
const emit = defineEmits(["choose"])
9+
const emit = defineEmits<{
10+
choose: [Option]
11+
}>()
912
10-
const props = defineProps({
11-
step: {
12-
type: Object,
13-
required: true,
14-
},
15-
active: {
16-
type: Boolean,
17-
default: false,
18-
},
19-
})
13+
defineProps<{
14+
step: Step
15+
active?: boolean
16+
}>()
2017
2118
const containerRef = useTemplateRef("container")
2219
2320
onMounted(() => {
24-
const { top, bottom } = containerRef.value.getBoundingClientRect()
21+
const { top } = containerRef.value!.getBoundingClientRect()
2522
const minVisibleHeight = 50
2623
const isVisible = top + minVisibleHeight < window.innerHeight
27-
if (!isVisible) containerRef.value.scrollIntoView({ behavior: "smooth" })
24+
if (!isVisible) containerRef.value!.scrollIntoView({ behavior: "smooth" })
2825
})
2926
</script>
3027

@@ -46,12 +43,12 @@ onMounted(() => {
4643
v-for="option in step.options"
4744
:key="option.hash"
4845
:option="option"
49-
@click="$emit('choose', option)"
46+
@click="emit('choose', option)"
5047
/>
5148
</div>
5249
<p v-if="debug" class="small">
53-
<a :href="'vscode://file/' + step.fullPath.replaceAll('\\', '/')">
54-
{{ step.filename }}
50+
<a :href="'vscode://file/' + step.fullPath!.replaceAll('\\', '/')">
51+
{{ step.filename! }}
5552
</a>
5653
</p>
5754
</div>

src/components/TroubleshooterStepOption.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script setup>
1+
<script setup lang="ts">
22
import { inject } from "vue"
33
44
defineProps({

src/globals.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
declare namespace bootstrap {
2+
interface Modal {
3+
hide()
4+
}
5+
6+
const Modal: {
7+
getInstance(el: HTMLElement): Modal
8+
}
9+
}
10+
11+
function plausible(
12+
eventName: string,
13+
options?: {
14+
props?: { [propName: string]: string | number | boolean }
15+
},
16+
): void

src/troubleshooter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference path="../plugins/troubleshooter/client.d.ts" />
22
import pages from "virtual:troubleshooter"
33

4-
interface Option {
4+
export interface Option {
55
id: string
66
label: string
77
summary: string
@@ -12,13 +12,15 @@ interface Option {
1212
selected: boolean
1313
}
1414

15-
interface Step {
15+
export interface Step {
1616
content: string
1717
number: number
1818
hash: string
1919
options?: Option[]
2020
selectedOption?: Option
2121
tags?: string[]
22+
filename?: string // only in dev
23+
fullPath?: string // only in dev
2224
}
2325

2426
function makeStep(pageId: number, hash?: string, number?: number): Step {

tsconfig.app.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
"@/*": [
1515
"./src/*"
1616
]
17-
}
18-
}
17+
},
18+
"lib": [
19+
"ES2021",
20+
"DOM",
21+
],
22+
},
1923
}

0 commit comments

Comments
 (0)