Skip to content

Cannot reference MlCopilotClientMessage child type #366

@lee-at-zoo-corp

Description

@lee-at-zoo-corp

It's impossible to reference the child type

{
    /** The content of the user's message. */
    content: string;
    current_files?: {
        [key: string]: number[];
    };
    /**
     * {
     *   "nullable": true,
     *   "description": "The project name, if any. This can be used to associate the message with a specific project."
     * }
     */
    project_name?: string;
    /** The source ranges the user suggested to change. If empty, the content (prompt) will be used and is required. */
    source_ranges?: SourceRangePrompt[];
    type: 'user';
}

Without having to redefine it.

This makes type narrowing more difficult and causes duplicate types which has been voiced to be particularly annoying.

I don't know the derivation happens but to fix this, type MlCopilotClientMessageUser = ... would solve the issue.

Edit: It's possible to use conditional typing to extract out the type but it should not be necessary to do type gymnastics to get access:

type MlCopilotClientMessageUser<T = MlCopilotClientMessage> = T extends { type: 'user' }
? T
: never

function isMlCopilotUserRequest(x: unknown): x is MlCopilotClientMessageUser {
  return 'type' in x && x.type === 'user'
}

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions