Skip to content

Commit b198126

Browse files
committed
chore: fix types error
1 parent 04ff8ab commit b198126

File tree

12 files changed

+5928
-65
lines changed

12 files changed

+5928
-65
lines changed

packages/client/src/components/AssetsBlock.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
video: 'i-carbon-video',
1919
audio: 'i-carbon-document-audio',
2020
other: 'i-carbon-document-unknown'
21-
}
21+
} as any
2222
23-
let assetInner = null
23+
let assetInner:any = {}
2424
$:if(asset){
2525
assetInner = asset
2626
}
2727
28-
let textContentInner = null
28+
let textContentInner: string = ''
2929
$:if(textContent){
3030
textContentInner = textContent
3131
}

packages/client/src/components/AssetsDetail.svelte

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import DividerTitle from "./DividerTitle.svelte";
33
import { KMessage, KIcon, KButton } from "@ikun-ui/core";
44
import AssetsPreview from "./AssetsPreview.svelte";
55
import type { AssetInfo } from "@ikun-svelte-devtools/shared";
6+
// @ts-ignore
67
import {useDevtoolsClient} from "../composables/client";
78
import { rpc } from "../composables/rpc";
89
import { formatDate, relativeTime } from '@baiwusanyu/utils-date'
@@ -20,38 +21,36 @@ export let asset:(AssetInfo & {fileName: string}) = {
2021
const client = useDevtoolsClient()
2122
const origin = window.parent.location.origin
2223
23-
let imageMeta = null
24+
let imageMeta: {width: number, height: number} = { width: 0, height: 0 }
2425
let fileSize = normalizeSizeUnits(asset.size)
2526
const getImageMeta = () => {
2627
if (asset.type !== 'image')
2728
return undefined
28-
return rpc.getImageMeta(asset.filePath).then(res => {
29-
imageMeta = res
29+
return rpc.getImageMeta(asset.filePath).then((res: unknown) => {
30+
imageMeta = res as {width: number, height: number}
3031
})
3132
}
32-
let aspectRatio = null
3333
34-
35-
let textContent = null
34+
let textContent: string = ''
3635
const getTextContent = async () => {
3736
if (asset.type !== 'text')
3837
return undefined
39-
rpc.getTextAssetContent(asset.filePath).then(res => {
40-
textContent = res
38+
rpc.getTextAssetContent(asset.filePath).then((res: unknown) => {
39+
textContent = res as string
4140
})
4241
}
4342
44-
let allowList = []
43+
let allowList: string[] = []
4544
const getAllowList = async () => {
4645
if (asset.type !== 'text')
4746
return undefined
48-
rpc.getAllowList().then(res => {
49-
allowList = res
47+
rpc.getAllowList().then((res: unknown) => {
48+
allowList = res as string[]
5049
})
5150
}
5251
getAllowList()
5352
54-
const handleDownload = (url: string, filePath) => {
53+
const handleDownload = (url: string, filePath: string) => {
5554
if(allowList.length > 0 && !isPathInArrayOrSubPath(allowList, filePath)){
5655
KMessage.warning({
5756
content: 'Target cannot be downloaded or opened due to svelte-kit security policy'
@@ -67,7 +66,7 @@ const handleDownload = (url: string, filePath) => {
6766
})
6867
}
6968
70-
const handleOpen= (url: string, filePath) => {
69+
const handleOpen= (url: string, filePath: string) => {
7170
if(allowList.length > 0 && !isPathInArrayOrSubPath(allowList, filePath)){
7271
KMessage.warning({
7372
content: 'Target cannot be downloaded or opened due to svelte-kit security policy'
@@ -83,7 +82,7 @@ const handleOpen= (url: string, filePath) => {
8382
})
8483
}
8584
86-
function isPathInArrayOrSubPath(pathArray, targetPath) {
85+
function isPathInArrayOrSubPath(pathArray: string[], targetPath: string) {
8786
// 遍历路径数组
8887
for (let i = 0; i < pathArray.length; i++) {
8988
let currentPath = pathArray[i];
@@ -120,7 +119,6 @@ $: if (asset.filePath && asset.type){
120119
</span>
121120
<KIcon
122121
btn
123-
aria-hidden="true"
124122
on:click={() => client.inspector.openInEditor(location.origin, asset.filePath, 1, 1)}
125123
cls="hover-icon"
126124
width="20px"
@@ -149,7 +147,6 @@ $: if (asset.filePath && asset.type){
149147
cls="hover-icon"
150148
color="text-tx-light"
151149
width="20px"
152-
aria-hidden="true"
153150
on:click={()=>handleOpen(asset.publicPath, asset.filePath)}
154151
height="20px"
155152
attrs={{title: 'open in browser'}}
@@ -173,14 +170,6 @@ $: if (asset.filePath && asset.type){
173170
</td>
174171
<td class="p-1">{ imageMeta.width } x { imageMeta.height }</td>
175172
</tr>
176-
{#if aspectRatio}
177-
<tr>
178-
<td class="w-30 ws-nowrap p-1 pr5 text-right op50">
179-
Aspect Ratio
180-
</td>
181-
<td class="p-1">{aspectRatio}</td>
182-
</tr>
183-
{/if}
184173
{/if}
185174
<tr>
186175
<td class="w-30 ws-nowrap p-1 pr5 text-right op50">

packages/client/src/components/SideNav.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
activeIndex = index
1515
}
1616
17-
const handleClick = (index: number, tab) => {
17+
const handleClick = (index: number, tab:{path: string, evt: <T>(arg: T) => void}) => {
1818
setActiveIndex(index)
1919
if(!tab.path && tab.evt){
2020
tab.evt(hookApi.hook)

packages/client/src/components/TerminalView.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { hookApi } from '../composables/hook'
77
import { tick } from "svelte";
88
export let modelValue = false
9-
let container = null
9+
let container: null | HTMLElement = null
1010
let term: Terminal
1111
1212
$:if(modelValue){
@@ -22,7 +22,7 @@
2222
})
2323
const fitAddon = new FitAddon()
2424
term.loadAddon(fitAddon)
25-
term.open(container)
25+
term.open(container!)
2626
fitAddon.fit()
2727
2828
hookApi.hook.on('__svelte-devtools:terminal:data__', (data: string) => {
@@ -37,6 +37,6 @@
3737
}
3838
</script>
3939
<KMask value={modelValue}>
40-
<div bind:this = {container}>
40+
<div bind:this= {container}>
4141
</div>
4242
</KMask>

packages/client/src/composables/tabs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export function useCategorizedTabs() {
125125
return setTabByConfig(builtinTabs);
126126
}
127127

128-
function setTabByConfig(tabs) {
128+
function setTabByConfig(tabs: BuiltinTab[]) {
129129
const config = getConfig();
130130
return tabs.map((v, index) => {
131131
v.hide = config.tabsHide[index];

packages/client/src/views/assets.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ async function getAssets() {
2323
}
2424
getAssets()
2525
26-
function classifyAssets(value){
26+
function classifyAssets(value:(AssetInfo & {fileName: string})){
2727
const basePath = value.path.split('/');
28-
(value as (AssetInfo & {fileName: string})).fileName = basePath.pop()
28+
value.fileName = basePath.pop() || ''
2929
let key = basePath.join('/') || '/'
3030
if(!assetsGrid[key]){
3131
assetsGrid[key] = []
@@ -85,7 +85,7 @@ const iconDict = {
8585
video: 'i-carbon-video',
8686
audio: 'i-carbon-document-audio',
8787
other: 'i-carbon-document-unknown'
88-
}
88+
} as any
8989
</script>
9090
<div class="flex flex-col h-full">
9191
<div class="w-full pt-6 px-4 pb-2 shadow">

packages/client/src/views/graph.svelte

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,25 @@ import {
2121
} from "@ikun-ui/core";
2222
import {rpc} from "../composables/rpc";
2323
import {darkLight} from "@ikun-svelte-devtools/utils-client";
24+
// @ts-ignore
2425
import { useDevtoolsClient } from "../composables/client";
25-
26+
import type {ModuleInfo, SvelteDevtoolsHostClient} from '@ikun-svelte-devtools/shared';
2627
let rootPath = ''
2728
const modulesMap = new Map<string, { filePath: string }>()
28-
rpc.root().then(res => {
29+
rpc.root().then((res: any) => {
2930
rootPath = res
30-
}).catch(err => {
31+
}).catch((err: Error) => {
3132
console.error(err)
3233
})
3334
3435
let keyPress = false
35-
const handleKeyPressDown = (event) => {
36+
const handleKeyPressDown = (event: KeyboardEvent) => {
3637
if(event.key === 'Alt' || event.key === 'Meta' || event.key === 'Cmd'){
3738
keyPress = true
3839
}
3940
}
4041
41-
const handleKeyPressUp = (event) => {
42+
const handleKeyPressUp = (event: KeyboardEvent) => {
4243
if(event.key === 'Alt' || event.key === 'Meta' || event.key === 'Cmd'){
4344
keyPress = false
4445
}
@@ -48,14 +49,14 @@ onDestroy(() => {
4849
document.removeEventListener('keyup', handleKeyPressUp)
4950
})
5051
/********* render chart ***********/
51-
const handleDataToChartData = (initData) =>{
52+
const handleDataToChartData = (initData: {data: ModuleInfo[], main: ModuleInfo[]}) =>{
5253
5354
if (!initData)
5455
return { node: [], edges: [] }
5556
5657
const { data, main } = initData
5758
const { level } = getGraphConfig()
58-
const nodes: Data['nodes'] = data.map((mod) => {
59+
const nodes: Data['nodes'] = (data).map((mod) => {
5960
const path = mod.id.replace(/\?.*$/, '').replace(/#.*$/, '')
6061
const pathSegments = path.split('/')
6162
const id = mod.id
@@ -80,7 +81,7 @@ const handleDataToChartData = (initData) =>{
8081
: darkLight() === 'dark' ? 'white' : 'black',
8182
multi: 'html',
8283
},
83-
shape: mod.id.includes('/node_modules/')
84+
shape: mod.id!.includes('/node_modules/')
8485
? 'hexagon'
8586
: mod.virtual
8687
? 'diamond'
@@ -106,20 +107,20 @@ const handleDataToChartData = (initData) =>{
106107
}
107108
108109
let searchValue = ''
109-
let graphData = null
110+
let graphData: any = null
110111
const searchNode = debounce((e) => {
111112
updateChart(e.detail)
112113
}, 300)
113114
114-
let lastSelectedNode = null
115-
let networkChart = null
115+
let lastSelectedNode: any = null
116+
let networkChart: InstanceType<typeof Network> | null = null
116117
const client = useDevtoolsClient()
117118
onMount(async () => {
118119
graphData = await getGraphData()
119120
let finalGraphData = initGraphData('', graphData)
120121
121122
const container = document.getElementById('__svelte_devtools_graph')
122-
networkChart = new Network(container, handleDataToChartData(finalGraphData) as Data, visNetworkOptions)
123+
networkChart = new Network(container!, handleDataToChartData(finalGraphData) as Data, visNetworkOptions)
123124
124125
const resetNodeStyle = () => {
125126
// @ts-expect-error network body typing error
@@ -143,7 +144,7 @@ onMount(async () => {
143144
144145
const { highlight, openEditor } = getGraphConfig()
145146
if (openEditor.open && keyPress){
146-
return client.inspector.openInEditor(location.origin, modulesMap.get(nodeId)!.filePath, 1, 1)
147+
return (client as SvelteDevtoolsHostClient).inspector!.openInEditor(location.origin, modulesMap.get(nodeId)!.filePath, 1, 1)
147148
}
148149
149150
@@ -219,15 +220,15 @@ const handleSwitch = (value: boolean, type: 'h' | 'o') => {
219220
/****************** custom hover path level **********************/
220221
let hoverPathLevel = level.value
221222
let hoverPathLevelCustom = level.levelCustom
222-
const handleHoverPathLevel = (data) => {
223+
const handleHoverPathLevel = (data:CustomEvent) => {
223224
hoverPathLevel = data.detail
224225
const curConfig = getGraphConfig()
225226
curConfig.level.value = hoverPathLevel
226227
// update config
227228
setGraphConfigCache(curConfig)
228229
updateChart()
229230
}
230-
const handlePathLevelCustom = (data) => {
231+
const handlePathLevelCustom = (data: CustomEvent) => {
231232
hoverPathLevelCustom = data.detail
232233
const curConfig = getGraphConfig()
233234
curConfig.level.levelCustom = hoverPathLevelCustom

packages/client/src/views/inspect.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import { rpc } from '../composables/rpc'
33
import IframeView from "../components/IframeView.svelte";
44
let url = ''
5-
rpc.inspectClientUrl().then(res=>{
6-
url = res
5+
rpc.inspectClientUrl().then((res: unknown )=>{
6+
url = res as string
77
}).catch(err =>{
88
console.error(err)
99
})

packages/client/src/views/overview.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
} from "@ikun-ui/core";
1212
let routesNum = 0
1313
rpc.getRoutesInfo().then((res) => {
14-
routesNum = res.length
14+
routesNum = (res as Array<unknown>).length
1515
})
1616
1717
let svelteVersion = '0.0.0'
1818
let svelteKitVersion = '0.0.0'
19-
rpc.getPackages().then((res) => {
20-
svelteVersion = res.packages['svelte'].version
21-
svelteKitVersion = res.packages['@sveltejs/kit'].version
19+
rpc.getPackages().then((res: unknown) => {
20+
svelteVersion = (res as Record<string, any>).packages['svelte'].version
21+
svelteKitVersion = (res as Record<string, any>).packages['@sveltejs/kit'].version
2222
})
2323
2424
let sfcNum = 0
2525
rpc.getSvelteSFCList().then((res) => {
26-
sfcNum = res.length
26+
sfcNum = (res as Array<unknown>).length
2727
})
2828
2929
const linkHover = {

packages/client/src/views/routes.svelte

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import {rpc} from "../composables/rpc.js";
55
import JSONTree from 'svelte-json-tree'
66
import Copy from "../components/Copy.svelte";
7-
let routes: Array<routeInfo> | null = []
7+
let routes: Array<routeInfo> = []
88
let selectRoute = {}
9-
rpc.getRoutesInfo().then((res) => {
10-
routes = res.sort((a, b) => {
9+
rpc.getRoutesInfo().then((res: unknown) => {
10+
routes = (res as Array<routeInfo>).sort((a, b) => {
1111
if (a.filePath < b.filePath) {
1212
return -1;
1313
}
@@ -19,10 +19,12 @@
1919
selectRoute = routes[0]
2020
})
2121
22-
const setActive = (index) => {
23-
routes.forEach(value => value.active = false)
24-
routes[index].active = true
25-
selectRoute = routes[index]
22+
const setActive = (index: number) => {
23+
if(routes){
24+
routes.forEach(value => value.active = false)
25+
routes[index].active = true
26+
selectRoute = routes[index]
27+
}
2628
}
2729
</script>
2830

0 commit comments

Comments
 (0)