Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 51b4a4e

Browse filesBrowse files
committed
chore: add type assertions for indexed access
1 parent b1ff702 commit 51b4a4e
Copy full SHA for 51b4a4e

6 files changed

+30-30Lines changed: 30 additions & 30 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/config.ts‎

Copy file name to clipboardExpand all lines: src/config.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export function defineVitestConfig(config: ViteUserConfig & { test?: VitestConfi
259259
? 'workspace'
260260
: await import('vitest/package.json', { with: { type: 'json' } }).then((r) => {
261261
const [major, minor] = (r.default || r).version.split('.')
262-
return Number.parseInt(major, 10) > 3 || (Number.parseInt(major, 10) === 3 && Number.parseInt(minor, 10) >= 2)
262+
return Number.parseInt(major!, 10) > 3 || (Number.parseInt(major!, 10) === 3 && Number.parseInt(minor!, 10) >= 2)
263263
})
264264
? 'projects'
265265
: 'workspace'
Collapse file

‎src/module/plugins/mock.ts‎

Copy file name to clipboardExpand all lines: src/module/plugins/mock.ts
+12-12Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const createMockPlugin = (ctx: MockPluginContext) => createUnplugin(() =>
8787
startOf(node),
8888
)
8989
}
90-
const importName = node.arguments[0]
90+
const importName = node.arguments[0]!
9191
if (!isLiteral(importName) || typeof importName.value !== 'string') {
9292
return this.error(
9393
new Error(
@@ -106,18 +106,18 @@ export const createMockPlugin = (ctx: MockPluginContext) => createUnplugin(() =>
106106
s.overwrite(
107107
isExpressionStatement(parent)
108108
? startOf(parent)
109-
: startOf(node.arguments[0]),
109+
: startOf(node.arguments[0]!),
110110
isExpressionStatement(parent)
111111
? endOf(parent)
112-
: endOf(node.arguments[1]),
112+
: endOf(node.arguments[1]!),
113113
'',
114114
)
115115
mocksImport.push({
116116
name,
117117
import: importItem,
118118
factory: code.slice(
119-
startOf(node.arguments[1]),
120-
endOf(node.arguments[1]),
119+
startOf(node.arguments[1]!),
120+
endOf(node.arguments[1]!),
121121
),
122122
})
123123
}
@@ -134,7 +134,7 @@ export const createMockPlugin = (ctx: MockPluginContext) => createUnplugin(() =>
134134
startOf(node),
135135
)
136136
}
137-
const componentName = node.arguments[0]
137+
const componentName = node.arguments[0]!
138138
if (!isLiteral(componentName) || typeof componentName.value !== 'string') {
139139
return this.error(
140140
new Error(
@@ -152,17 +152,17 @@ export const createMockPlugin = (ctx: MockPluginContext) => createUnplugin(() =>
152152
s.overwrite(
153153
isExpressionStatement(parent)
154154
? startOf(parent)
155-
: startOf(node.arguments[1]),
155+
: startOf(node.arguments[1]!),
156156
isExpressionStatement(parent)
157157
? endOf(parent)
158-
: endOf(node.arguments[1]),
158+
: endOf(node.arguments[1]!),
159159
'',
160160
)
161161
mocksComponent.push({
162162
path: path,
163163
factory: code.slice(
164-
startOf(node.arguments[1]),
165-
endOf(node.arguments[1]),
164+
startOf(node.arguments[1]!),
165+
endOf(node.arguments[1]!),
166166
),
167167
})
168168
}
@@ -263,7 +263,7 @@ export const createMockPlugin = (ctx: MockPluginContext) => createUnplugin(() =>
263263
const vitestPlugins = plugins.filter(p => (p.name === 'vite:mocks' || p.name.startsWith('vitest:')) && (p.enforce || ('order' in p && p.order)) === 'post')
264264
const lastNuxt = findLastIndex(
265265
plugins,
266-
i => i.name?.startsWith('nuxt:'),
266+
i => !!i?.name?.startsWith('nuxt:'),
267267
)
268268
if (lastNuxt === -1) return
269269
for (const plugin of vitestPlugins) {
@@ -279,7 +279,7 @@ export const createMockPlugin = (ctx: MockPluginContext) => createUnplugin(() =>
279279
})
280280

281281
// Polyfill Array.prototype.findLastIndex for legacy Node.js
282-
function findLastIndex<T>(arr: T[], predicate: (item: T) => boolean) {
282+
function findLastIndex<T>(arr: T[], predicate: (item?: T) => boolean) {
283283
for (let i = arr.length - 1; i >= 0; i--) {
284284
if (predicate(arr[i])) return i
285285
}
Collapse file

‎src/runtime-utils/mock.ts‎

Copy file name to clipboardExpand all lines: src/runtime-utils/mock.ts
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ export function registerEndpoint(url: string, options: EventHandler | { handler:
5555
window.__registry.add(url)
5656

5757
app.use('/_' + url, defineEventHandler((event) => {
58-
const latestHandler = [...endpointRegistry[url]].reverse().find(config => config.method ? event.method === config.method : true)
58+
const latestHandler = [...endpointRegistry[url] || []].reverse().find(config => config.method ? event.method === config.method : true)
5959
return latestHandler?.handler(event)
6060
}), {
6161
match(_, event) {
62-
return endpointRegistry[url]?.some(config => config.method ? event?.method === config.method : true)
62+
return endpointRegistry[url]?.some(config => config.method ? event?.method === config.method : true) ?? false
6363
},
6464
})
6565
}
6666

6767
return () => {
68-
endpointRegistry[url].splice(endpointRegistry[url].indexOf(config), 1)
69-
if (endpointRegistry[url].length === 0) {
68+
endpointRegistry[url]?.splice(endpointRegistry[url].indexOf(config), 1)
69+
if (endpointRegistry[url]?.length === 0) {
7070
// @ts-expect-error private property
7171
window.__registry.delete(url)
7272
}
Collapse file

‎src/runtime-utils/mount.ts‎

Copy file name to clipboardExpand all lines: src/runtime-utils/mount.ts
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,17 @@ export async function mountSuspended<T>(
161161
propsContext[key] = passedProps[key]
162162
}
163163
if (methods && typeof methods === 'object') {
164-
for (const key in methods) {
165-
renderContext[key] = methods[key].bind(renderContext)
164+
for (const [key, value] of Object.entries(methods)) {
165+
renderContext[key] = value.bind(renderContext)
166166
}
167167
}
168168
if (computed && typeof computed === 'object') {
169-
for (const key in computed) {
170-
if ('get' in computed[key]) {
171-
renderContext[key] = computed[key].get.call(renderContext)
169+
for (const [key, value] of Object.entries(computed)) {
170+
if ('get' in value) {
171+
renderContext[key] = value.get.call(renderContext)
172172
}
173173
else {
174-
renderContext[key] = computed[key].call(renderContext)
174+
renderContext[key] = value.call(renderContext)
175175
}
176176
}
177177
}
Collapse file

‎src/runtime-utils/render.ts‎

Copy file name to clipboardExpand all lines: src/runtime-utils/render.ts
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,17 @@ export async function renderSuspended<T>(component: T, options?: RenderOptions<T
172172
propsContext[key] = passedProps[key]
173173
}
174174
if (methods && typeof methods === 'object') {
175-
for (const key in methods) {
176-
renderContext[key] = methods[key].bind(renderContext)
175+
for (const [key, value] of Object.entries(methods)) {
176+
renderContext[key] = value.bind(renderContext)
177177
}
178178
}
179179
if (computed && typeof computed === 'object') {
180-
for (const key in computed) {
181-
if ('get' in computed[key]) {
182-
renderContext[key] = computed[key].get.call(renderContext)
180+
for (const [key, value] of Object.entries(computed)) {
181+
if ('get' in value) {
182+
renderContext[key] = value.get.call(renderContext)
183183
}
184184
else {
185-
renderContext[key] = computed[key].call(renderContext)
185+
renderContext[key] = value.call(renderContext)
186186
}
187187
}
188188
}
Collapse file

‎src/runtime/shared/environment.ts‎

Copy file name to clipboardExpand all lines: src/runtime/shared/environment.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function setupWindow(win: NuxtWindow, environmentOptions: { nuxt: N
5959

6060
win.fetch = async (url, init) => {
6161
if (typeof url === 'string') {
62-
const base = url.split('?')[0]
62+
const base = url.split('?')[0]!
6363
if (registry.has(base) || registry.has(url)) {
6464
url = '/_' + url
6565
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.