Skip to content

Commit 9a6c882

Browse files
authored
refactor: add type assertions + guards (#902)
1 parent 3d22410 commit 9a6c882

File tree

17 files changed

+43
-37
lines changed

17 files changed

+43
-37
lines changed

packages/devtools-ui-kit/src/unocss.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export function unocssPreset(): Preset {
2929
}),
3030
rules: [
3131
[/^n-(.*)$/, ([, body]: string[], { theme }: RuleContext<Theme>) => {
32-
const color = parseColor(body, theme)
32+
const color = parseColor(body!, theme)
3333
if (color?.cssColor?.type === 'rgb' && color.cssColor.components) {
3434
return {
3535
'--nui-c-context': `${color.cssColor.components.join(',')}`,
3636
}
3737
}
3838
}],
39-
[/^n-(.*)$/, fonts[1][1] as any],
39+
[/^n-(.*)$/, fonts[1]![1] as any],
4040
['n-dashed', { 'border-style': 'dashed' }],
4141
['n-solid', {
4242
'background-color': 'rgba(var(--nui-c-context), 1) !important',

packages/devtools/client/components/AssetDetails.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ const renameDialog = ref(false)
157157
const newName = ref('')
158158
async function renameAsset() {
159159
const parts = asset.value.filePath.split('/')
160-
const oldName = parts.slice(-1)[0].split('.').slice(0, -1).join('.')
160+
const oldName = parts.slice(-1)[0]?.split('.').slice(0, -1).join('.')
161161
162162
if (!newName.value || newName.value === oldName) {
163163
return devtoolsUiShowNotification({
@@ -168,7 +168,7 @@ async function renameAsset() {
168168
}
169169
170170
try {
171-
const extension = parts.slice(-1)[0].split('.').slice(-1)[0]
171+
const extension = parts.slice(-1)[0]?.split('.').slice(-1)[0]
172172
const fullPath = `${parts.slice(0, -1).join('/')}/${newName.value}.${extension}`
173173
await rpc.renameStaticAsset(await ensureDevAuthToken(), asset.value.filePath, fullPath)
174174
asset.value = undefined as any

packages/devtools/client/components/CommandPalette.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ function moveSelected(delta: number) {
3737
}
3838
3939
function scrollToITem() {
40-
const item = document.getElementById(filtered.value[selectedIndex.value]?.id)
40+
const id = filtered.value[selectedIndex.value]?.id
41+
if (!id)
42+
return
43+
44+
const item = document.getElementById(id)
4145
item?.scrollIntoView({
4246
block: 'center',
4347
})

packages/devtools/client/components/DataSchemaDrawer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function copyToClipboard() {
9797
<NSwitch
9898
v-for="item, index of options"
9999
:key="item.name"
100-
v-model="options[index].defaultValue"
100+
v-model="options[index]!.defaultValue"
101101
flex="~ gap-2" rounded px2 py2
102102
>
103103
<span text-xs capitalize op75>

packages/devtools/client/components/ServerRouteDetails.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const finalPath = computed(() => {
163163
})
164164
const finalURL = computed(() => domain.value + finalPath.value)
165165
166-
function parseInputs(inputs: ServerRouteInput[]) {
166+
function parseInputs(inputs: ServerRouteInput[] = []) {
167167
const formatted = Object.fromEntries(
168168
inputs.filter(({ active, key, value }) => active && key && value !== undefined).map(({ key, value }) => [key, value]),
169169
)
@@ -433,7 +433,7 @@ const copy = useCopy()
433433
{{ tab.name }}
434434
{{ tab?.length ? `(${tab.length})` : '' }}
435435
<span>
436-
{{ inputDefaults[tab.slug]?.length ? `(${inputDefaults[tab.slug].length})` : '' }}
436+
{{ inputDefaults[tab.slug]?.length ? `(${inputDefaults[tab.slug]!.length})` : '' }}
437437
</span>
438438
</div>
439439
</NButton>
@@ -485,9 +485,9 @@ const copy = useCopy()
485485
placeholder="Value..."
486486
:model-value="cookie.value"
487487
flex-1 n="primary"
488-
@input="updateCookie(cookie.key, ($event as any).target?.value)"
488+
@input="updateCookie(cookie.key!, ($event as any).target?.value)"
489489
/>
490-
<NButton title="Delete" n="red" @click="updateCookie(cookie.key, undefined)">
490+
<NButton title="Delete" n="red" @click="updateCookie(cookie.key!, undefined)">
491491
<NIcon icon="i-carbon-trash-can" />
492492
</NButton>
493493
</div>

packages/devtools/client/components/ServerTaskDetails.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ const finalPath = computed(() => {
115115
})
116116
const finalURL = computed(() => domain.value + finalPath.value)
117117
118-
function parseInputs(inputs: ServerRouteInput[]) {
118+
function parseInputs(inputs: ServerRouteInput[] = []) {
119119
const formatted = Object.fromEntries(
120120
inputs.filter(({ active, key, value }) => active && key && value !== undefined).map(({ key, value }) => [key, value]),
121121
)
@@ -272,7 +272,7 @@ const copy = useCopy()
272272
{{ tab.name }}
273273
{{ tab?.length ? `(${tab.length})` : '' }}
274274
<span>
275-
{{ inputDefaults[tab.slug]?.length ? `(${inputDefaults[tab.slug].length})` : '' }}
275+
{{ inputDefaults[tab.slug]?.length ? `(${inputDefaults[tab.slug]!.length})` : '' }}
276276
</span>
277277
</div>
278278
</NButton>

packages/devtools/client/components/TerminalPage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async function remove(id: string) {
1515
1616
watchEffect(() => {
1717
if (!terminalId.value && terminals.value?.length)
18-
terminalId.value = terminals.value[0].id
18+
terminalId.value = terminals.value[0]!.id
1919
})
2020
</script>
2121

packages/devtools/client/composables/timeline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function segmentTimelineEvents(events: TimelineEvent[]) {
4141
const layers: number[] = []
4242

4343
segment.duration = duration
44-
segment.previousGap = idx > 0 ? segment.start - segments[idx - 1].end : 0
44+
segment.previousGap = idx > 0 ? segment.start - segments[idx - 1]!.end : 0
4545
segment.events
4646
.forEach((event) => {
4747
const end = (event.end || event.start)

packages/devtools/client/pages/modules/server-routes.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const filterByCollection = computed(() => {
107107
}
108108
}
109109
110-
if (collectionNames.length > 0 && collectionNames[collectionNames.length - 1].includes('.'))
110+
if (collectionNames.length > 0 && collectionNames[collectionNames.length - 1]!.includes('.'))
111111
collectionNames.pop()
112112
113113
collectionNames.forEach((collectionName) => {
@@ -192,7 +192,7 @@ function capitalize(str: string) {
192192
<NSectionBlock
193193
v-for="tab of Object.keys(inputDefaults)"
194194
:key="tab"
195-
:text="`${capitalize(tab)} ${inputDefaults[tab].length ? `(${inputDefaults[tab].length})` : ''}`"
195+
:text="`${capitalize(tab)} ${inputDefaults[tab]?.length ? `(${inputDefaults[tab]!.length})` : ''}`"
196196
:padding="false"
197197
:icon="ServerRouteTabIcons[tab]"
198198
>

packages/devtools/client/pages/modules/server-tasks.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const inputDefaultsDrawer = ref(false)
3131
const serverTasks = useServerTasks()
3232
const tasks = computed<ServerTaskInfo[]>(() => Object.keys(serverTasks.value?.tasks ?? {}).map(taskKey => ({
3333
name: taskKey,
34-
...serverTasks.value!.tasks[taskKey],
34+
...serverTasks.value!.tasks[taskKey]!,
3535
type: 'task',
3636
})))
3737
@@ -121,7 +121,7 @@ const filterByCollection = computed(() => {
121121
const taskParts = item.name.split(':')
122122
const collectionNames = taskParts.concat()
123123
124-
if (collectionNames.length > 0 && collectionNames[collectionNames.length - 1].includes('.'))
124+
if (collectionNames.length > 0 && collectionNames[collectionNames.length - 1]?.includes('.'))
125125
collectionNames.pop()
126126
127127
collectionNames.forEach((collectionName) => {
@@ -215,7 +215,7 @@ function toggleView() {
215215
<span text-white op50>Merged as default for every task in DevTools</span>
216216
</div>
217217
<NSectionBlock
218-
:text="`Query ${inputDefaults.query.length ? `(${inputDefaults.query.length})` : ''}`"
218+
:text="`Query ${inputDefaults.query?.length ? `(${inputDefaults.query.length})` : ''}`"
219219
:padding="false"
220220
:icon="ServerRouteTabIcons.query"
221221
>

0 commit comments

Comments
 (0)