Skip to content

Commit 414b0e6

Browse files
committed
fix: ensure imported editor can be passed as prop without type error
1 parent 4b5ecc2 commit 414b0e6

File tree

7 files changed

+15
-23
lines changed

7 files changed

+15
-23
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
"types": "dist/repl.d.ts",
1212
"exports": {
1313
".": {
14+
"types": "./dist/repl.d.ts",
1415
"import": "./dist/vue-repl.js",
15-
"require": "./dist/ssr-stub.js",
16-
"types": "./dist/repl.d.ts"
16+
"require": "./dist/ssr-stub.js"
1717
},
1818
"./monaco-editor": {
19+
"types": "./dist/editor-types.d.ts",
1920
"import": "./dist/monaco-editor.js",
20-
"require": null,
21-
"types": "./dist/MonacoEditor.vue.d.ts"
21+
"require": null
2222
},
2323
"./codemirror-editor": {
24+
"types": "./dist/editor-types.d.ts",
2425
"import": "./dist/codemirror-editor.js",
25-
"require": null,
26-
"types": "./dist/CodeMirrorEditor.vue.d.ts"
26+
"require": null
2727
},
2828
"./style.css": "./dist/style.css",
2929
"./dist/style.css": "./dist/style.css"

scripts/cleanup.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
// This file is executed from npm script with project root as cwd.
22
import fs from 'node:fs'
33

4-
fs.renameSync(
5-
'dist/src/editor/CodeMirrorEditor.vue.d.ts',
6-
'dist/CodeMirrorEditor.vue.d.ts'
7-
)
8-
9-
fs.renameSync(
10-
'dist/src/editor/MonacoEditor.vue.d.ts',
11-
'dist/MonacoEditor.vue.d.ts'
12-
)
13-
14-
fs.renameSync('dist/src/editor/types.d.ts', 'dist/types.d.ts')
4+
fs.renameSync('dist/src/editor/types.d.ts', 'dist/editor-types.d.ts')
155

166
fs.rmSync('dist/src', { recursive: true })

src/Repl.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import SplitPane from './SplitPane.vue'
33
import Output from './output/Output.vue'
44
import { Store, ReplStore, SFCOptions } from './store'
55
import { provide, toRef } from 'vue'
6-
import { EditorComponentType } from './editor/types'
6+
import type EditorComponentType from './editor/types'
77
import EditorContainer from './editor/EditorContainer.vue'
88
99
export interface Props {

src/editor/EditorContainer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Message from '../Message.vue'
44
import { debounce } from '../utils'
55
import { inject } from 'vue'
66
import { Store } from '../store'
7-
import { EditorComponentType } from './types'
7+
import type EditorComponentType from './types'
88
99
const props = defineProps<{
1010
editorComponent: EditorComponentType

src/editor/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ interface EditorEmits {
1313
(e: 'change', code: string): void
1414
}
1515

16-
export type EditorComponentType = Component<EditorProps, EditorEmits> & {
16+
type EditorComponentType = Component<EditorProps, EditorEmits> & {
1717
editorType: 'monaco' | 'codemirror'
1818
}
19+
20+
export default EditorComponentType

src/output/Output.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Preview from './Preview.vue'
33
import { Store } from '../store'
44
import { inject, ref, computed } from 'vue'
55
import type { OutputModes } from './types'
6-
import { EditorComponentType } from '../editor/types'
6+
import type EditorComponentType from '../editor/types'
77
88
const props = defineProps<{
99
editorComponent: EditorComponentType

test/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createApp, h, watchEffect } from 'vue'
22
import { Repl, ReplStore } from '../src'
33
import MonacoEditor from '../src/editor/MonacoEditor.vue'
44
// import CodeMirrorEditor from '../src/editor/CodeMirrorEditor.vue'
5+
import EditorComponentType from '../src/editor/types'
56
;(window as any).process = { env: {} }
67

78
const App = {
@@ -37,10 +38,9 @@ const App = {
3738
// store.setVueVersion('3.2.8')
3839

3940
return () =>
40-
//@ts-ignore
4141
h(Repl, {
4242
store,
43-
editor: MonacoEditor,
43+
editor: MonacoEditor as any as EditorComponentType,
4444
// layout: 'vertical',
4545
ssr: true,
4646
sfcOptions: {

0 commit comments

Comments
 (0)