Skip to content

Commit e2a9bbc

Browse files
authored
Merge pull request #296 from ckeditor/fix-typings
Fix: Fix the component properties and event types. Internal: Add `tsconfig.json` to the demo. Internal: Lint only the `.ts` and `.vue` files.
2 parents 88bea11 + 893998c commit e2a9bbc

File tree

5 files changed

+50
-10
lines changed

5 files changed

+50
-10
lines changed

Diff for: demo/tsconfig.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"types": [
5+
"../src/plugin.ts"
6+
]
7+
},
8+
"include": [
9+
"**/*"
10+
]
11+
}

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"build": "vite build && vue-tsc --declaration --emitDeclarationOnly",
7979
"test": "vitest run --coverage",
8080
"test:watch": "vitest --ui --watch",
81-
"lint": "eslint \"{demo,src,tests}/**/*\"",
81+
"lint": "eslint \"{demo,src,tests}/**/*.{ts,vue}\"",
8282
"postinstall": "node ./scripts/postinstall.js",
8383
"changelog": "node ./scripts/changelog.js",
8484
"release:prepare-packages": "node ./scripts/preparepackages.js",

Diff for: src/ckeditor.vue

+3-8
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,17 @@ import {
1919
onBeforeUnmount
2020
} from 'vue';
2121
import type { Editor, EditorConfig, EventInfo } from 'ckeditor5';
22+
import type { Props, ExtractEditorType } from './types.js';
2223
23-
type EditorType = TEditor extends { create( ...args: any[] ): Promise<infer E> } ? E : never;
24+
type EditorType = ExtractEditorType<TEditor>;
2425
2526
defineOptions( {
2627
name: 'CKEditor'
2728
} );
2829
2930
const model = defineModel( 'modelValue', { type: String, default: '' } );
3031
31-
const props = withDefaults( defineProps<{
32-
editor: TEditor;
33-
config?: EditorConfig;
34-
tagName?: string;
35-
disabled?: boolean;
36-
disableTwoWayDataBinding?: boolean;
37-
}>(), {
32+
const props = withDefaults( defineProps<Props<TEditor>>(), {
3833
config: () => ( {} ),
3934
tagName: 'div',
4035
disabled: false,

Diff for: src/types.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
import type { EditorConfig } from 'ckeditor5';
7+
8+
/**
9+
* This file contains types for the CKEditor 5 Vue component.
10+
* These types were moved to a separate file, because the `vue-tsc`
11+
* package couldn't generate the correct types for the component
12+
* when the types were in the component file. This is a workaround
13+
* that may be fixed in the next versions of `vue-tsc`.
14+
*/
15+
16+
/**
17+
* The props accepted by the `<ckeditor>` component.
18+
*/
19+
export interface Props<TEditor> {
20+
editor: TEditor;
21+
config?: EditorConfig;
22+
tagName?: string;
23+
disabled?: boolean;
24+
disableTwoWayDataBinding?: boolean;
25+
}
26+
27+
/**
28+
* The editor type extracted from the editor instance type.
29+
*/
30+
export type ExtractEditorType<TEditor> = TEditor extends { create( ...args: Array<any> ): Promise<infer E> }
31+
? E
32+
: never;

Diff for: tsconfig.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@
2626
"declaration": true,
2727
"declarationDir": "./dist"
2828
},
29-
"include": ["src/plugin.ts"]
29+
"include": [
30+
"src"
31+
]
3032
}

0 commit comments

Comments
 (0)