Skip to content

Commit 301a749

Browse files
committed
fix(vue-type-check): fix vue type check issues
- 🏷️ Added helper type `EditorMode` - 🏷️ Added the `boolAttrs` explicitly to the props to enhance type check - 🐛 Fixed vue type check errors
1 parent 16d562f commit 301a749

File tree

1 file changed

+44
-19
lines changed

1 file changed

+44
-19
lines changed

src/index.ts

+44-19
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import type { App, PropType } from 'vue-demi'
66
import { conclude, resolveConfig } from 'vue-global-config'
77
import { PascalCasedName as name } from '../package.json'
88

9-
const propsGlobal: Record<keyof any, any> = {}
10-
const attrsGlobal: Record<keyof any, any> = {}
9+
export type EditorMode = `${Mode}`
10+
11+
const propsGlobal: Record<string, any> = {}
12+
const attrsGlobal: Record<string, any> = {}
1113
const modeDefault = 'tree'
1214
const modelValueProp = isVue3 ? 'modelValue' : 'value'
1315
const updateModelValue = isVue3 ? 'update:modelValue' : 'input'
@@ -25,38 +27,61 @@ const boolAttrs = [
2527
export default defineComponent({
2628
name,
2729
install(app: App, options = {}): void {
28-
const { props, attrs } = resolveConfig(options, { props: this.props as any })
30+
const { props, attrs } = resolveConfig(options, { props: this.$props as any })
2931
Object.assign(propsGlobal, props)
3032
Object.assign(attrsGlobal, attrs)
3133
app.component(name, this)
3234
},
3335
props: {
34-
[modelValueProp]: {},
36+
[modelValueProp]: Object,
3537
mode: {
36-
type: String as PropType<Mode>,
38+
type: String as PropType<EditorMode>,
3739
},
3840
debounce: {
39-
type: Number as PropType<number>,
41+
type: Number,
4042
},
4143
stringified: {
42-
type: Boolean as PropType<boolean>,
44+
type: Boolean,
45+
default: undefined,
46+
},
47+
mainMenuBar: {
48+
type: Boolean,
49+
default: undefined,
50+
},
51+
navigationBar: {
52+
type: Boolean,
53+
default: undefined,
54+
},
55+
statusBar: {
56+
type: Boolean,
57+
default: undefined,
58+
},
59+
askToFormat: {
60+
type: Boolean,
61+
default: undefined,
62+
},
63+
readOnly: {
64+
type: Boolean,
65+
default: undefined,
66+
},
67+
escapeControlCharacters: {
68+
type: Boolean,
69+
default: undefined,
70+
},
71+
escapeUnicodeCharacters: {
72+
type: Boolean,
73+
default: undefined,
74+
},
75+
flattenColumns: {
76+
type: Boolean,
4377
default: undefined,
4478
},
45-
...Object.fromEntries(
46-
boolAttrs.map(boolAttr => [
47-
boolAttr,
48-
{
49-
type: Boolean as PropType<boolean>,
50-
default: undefined,
51-
},
52-
]),
53-
),
5479
},
5580
emits: {
5681
[updateModelValue](_payload: any) {
5782
return true
5883
},
59-
'update:mode': function (_payload: Mode) {
84+
'update:mode': function (_payload: EditorMode) {
6085
return true
6186
},
6287
},
@@ -68,13 +93,13 @@ export default defineComponent({
6893
const modeComputed = ref()
6994
watchEffect(() => {
7095
modeComputed.value = conclude([props.mode, propsGlobal.mode], {
71-
type: String as PropType<Mode>,
96+
type: String as PropType<EditorMode>,
7297
})
7398
jsonEditor.value?.updateProps({
7499
mode: modeComputed.value || modeDefault,
75100
})
76101
})
77-
const onChangeMode = (mode: Mode) => {
102+
const onChangeMode = (mode: EditorMode) => {
78103
emit('update:mode', mode)
79104
}
80105
// Synchronize the local `mode` with the global one

0 commit comments

Comments
 (0)