Skip to content

Commit 007b5c0

Browse files
committed
Convert all Vue files to TypeScript
1 parent b3b5bb2 commit 007b5c0

File tree

7 files changed

+60
-45
lines changed

7 files changed

+60
-45
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: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
<script setup>
1+
<script setup lang="ts">
22
import { useTemplateRef } from "vue"
33
4-
const { report } = defineProps({
5-
report: {
6-
type: String,
7-
required: true,
8-
},
9-
})
4+
const { report } = defineProps<{
5+
report: string
6+
}>()
107
11-
const formRef = useTemplateRef("issueForm")
8+
const formRef = useTemplateRef<HTMLFormElement>("issueForm")
9+
const modalRef = useTemplateRef<HTMLDivElement>("modal")
1210
1311
function createIssue() {
14-
const formData = new FormData(formRef.value)
12+
const formData = new FormData(formRef.value!)
1513
16-
const title = formData.get("title")
14+
const title = formData.get("title") as string
1715
let body = ""
1816
1917
const description = formData.get("description")
@@ -48,12 +46,12 @@ function createIssue() {
4846
console.log("URL", url)
4947
window.open(url, "_blank")
5048
51-
bootstrap.Modal.getInstance(this.$el).hide()
49+
bootstrap.Modal.getInstance(modalRef.value!).hide()
5250
}
5351
</script>
5452

5553
<template>
56-
<div class="modal fade">
54+
<div class="modal fade" ref="modal">
5755
<div class="modal-dialog modal-dialog-scrollable modal-lg">
5856
<form class="modal-content" ref="issueForm" @submit.prevent="createIssue">
5957
<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: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
<script setup>
1+
<script setup lang="ts">
2+
import type { Option } from "@/troubleshooter"
23
import { inject } from "vue"
34
4-
defineProps({
5-
option: {
6-
type: Object,
7-
required: true,
8-
},
9-
})
5+
defineProps<{
6+
option: Option
7+
}>()
108
119
const debug = inject("debug")
1210

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)