Skip to content

Commit 0f8865e

Browse files
committed
remove unnecessary token casting
1 parent fef69a3 commit 0f8865e

File tree

1 file changed

+5
-26
lines changed
  • packages/jupyterlab-chat-extension/src

1 file changed

+5
-26
lines changed

packages/jupyterlab-chat-extension/src/index.ts

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { Contents } from '@jupyterlab/services';
4646
import { ISettingRegistry } from '@jupyterlab/settingregistry';
4747
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
4848
import { launchIcon } from '@jupyterlab/ui-components';
49-
import { PromiseDelegate, Token } from '@lumino/coreutils';
49+
import { PromiseDelegate } from '@lumino/coreutils';
5050
import {
5151
ChatPanel,
5252
ChatWidgetFactory,
@@ -67,19 +67,9 @@ import {
6767
import { chatCommandRegistryPlugin } from './chat-commands/plugins';
6868
import { emojiCommandsPlugin } from './chat-commands/providers/emoji';
6969
import { mentionCommandsPlugin } from './chat-commands/providers/user-mention';
70-
import { DocumentChange, YDocument } from '@jupyter/ydoc';
7170

7271
const FACTORY = 'Chat';
7372

74-
// Cast ICollaborativeContentProvider token so TypeScript accepts it in plugin optional/requires arrays.
75-
// The arrays expect Token<any> from JupyterLab's @lumino/coreutils, but our token is from
76-
// @jupyter/collaborative-drive's @lumino/coreutils. These have separate Token class declarations
77-
// with their own private '_tokenStructuralPropertyT' properties, making TypeScript treat them as
78-
// distinct incompatible types even though they work identically. This is safe because tokens are just
79-
// dependency injection identifiers - the actual ICollaborativeContentProvider instance works correctly.
80-
const ICollaborativeContentProviderToken =
81-
ICollaborativeContentProvider as unknown as Token<any>;
82-
8373
const pluginIds = {
8474
activeCellManager: 'jupyterlab-chat-extension:activeCellManager',
8575
attachmentOpenerRegistry: 'jupyterlab-chat-extension:attachmentOpener',
@@ -121,7 +111,7 @@ const docFactories: JupyterFrontEndPlugin<IChatFactory> = {
121111
IActiveCellManagerToken,
122112
IAttachmentOpenerRegistry,
123113
IChatCommandRegistry,
124-
ICollaborativeContentProviderToken,
114+
ICollaborativeContentProvider,
125115
IDefaultFileBrowser,
126116
IInputToolbarRegistryFactory,
127117
ILayoutRestorer,
@@ -277,14 +267,7 @@ const docFactories: JupyterFrontEndPlugin<IChatFactory> = {
277267
app.docRegistry.addFileType(chatFileType);
278268

279269
if (drive) {
280-
// Cast YChat return type to match SharedDocumentFactory's expected return type.
281-
// SharedDocumentFactory expects YDocument<DocumentChange>, but YChat.create() returns
282-
// YDocument<IChatChanges>. Since IChatChanges extends DocumentChange, the cast is valid.
283-
// TypeScript's generic invariance requires the cast as YDocument<Subtype> isn't assignable
284-
// to YDocument<Supertype> even when Subtype extends Supertype.
285-
const chatFactory = () => {
286-
return YChat.create() as unknown as YDocument<DocumentChange>;
287-
};
270+
const chatFactory = () => YChat.create();
288271
drive.sharedModelFactory.registerDocumentFactory('chat', chatFactory);
289272
}
290273

@@ -376,7 +359,7 @@ const chatCommands: JupyterFrontEndPlugin<void> = {
376359
id: pluginIds.chatCommands,
377360
description: 'The commands to create or open a chat.',
378361
autoStart: true,
379-
requires: [ICollaborativeContentProviderToken, IChatFactory],
362+
requires: [ICollaborativeContentProvider, IChatFactory],
380363
optional: [
381364
IActiveCellManagerToken,
382365
IChatPanel,
@@ -690,11 +673,7 @@ const chatPanel: JupyterFrontEndPlugin<ChatPanel> = {
690673
description: 'The chat panel widget.',
691674
autoStart: true,
692675
provides: IChatPanel,
693-
requires: [
694-
IChatFactory,
695-
ICollaborativeContentProviderToken,
696-
IRenderMimeRegistry
697-
],
676+
requires: [IChatFactory, ICollaborativeContentProvider, IRenderMimeRegistry],
698677
optional: [
699678
IAttachmentOpenerRegistry,
700679
IChatCommandRegistry,

0 commit comments

Comments
 (0)