Skip to content

Fix: Fix component prop and event types. #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": [
"../src/plugin.ts"
]
},
"include": [
"**/*"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"build": "vite build && vue-tsc --declaration --emitDeclarationOnly",
"test": "vitest run --coverage",
"test:watch": "vitest --ui --watch",
"lint": "eslint \"{demo,src,tests}/**/*\"",
"lint": "eslint \"{demo,src,tests}/**/*.{ts,vue}\"",
"postinstall": "node ./scripts/postinstall.js",
"changelog": "node ./scripts/changelog.js",
"release:prepare-packages": "node ./scripts/preparepackages.js",
Expand Down
11 changes: 3 additions & 8 deletions src/ckeditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,17 @@ import {
onBeforeUnmount
} from 'vue';
import type { Editor, EditorConfig, EventInfo } from 'ckeditor5';
import type { Props, ExtractEditorType } from './types.js';

type EditorType = TEditor extends { create( ...args: any[] ): Promise<infer E> } ? E : never;
type EditorType = ExtractEditorType<TEditor>;

defineOptions( {
name: 'CKEditor'
} );

const model = defineModel( 'modelValue', { type: String, default: '' } );

const props = withDefaults( defineProps<{
editor: TEditor;
config?: EditorConfig;
tagName?: string;
disabled?: boolean;
disableTwoWayDataBinding?: boolean;
}>(), {
const props = withDefaults( defineProps<Props<TEditor>>(), {
config: () => ( {} ),
tagName: 'div',
disabled: false,
Expand Down
32 changes: 32 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/

import type { EditorConfig } from 'ckeditor5';

/**
* This file contains types for the CKEditor 5 Vue component.
* These types were moved to a separate file, because the `vue-tsc`
* package couldn't generate the correct types for the component
* when the types were in the component file. This is a workaround
* that may be fixed in the next versions of `vue-tsc`.
*/

/**
* The props accepted by the `<ckeditor>` component.
*/
export interface Props<TEditor> {
editor: TEditor;
config?: EditorConfig;
tagName?: string;
disabled?: boolean;
disableTwoWayDataBinding?: boolean;
}

/**
* The editor type extracted from the editor instance type.
*/
export type ExtractEditorType<TEditor> = TEditor extends { create( ...args: Array<any> ): Promise<infer E> }
? E
: never;
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@
"declaration": true,
"declarationDir": "./dist"
},
"include": ["src/plugin.ts"]
"include": [
"src"
]
}