-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Description
π Search Terms
never in record unknown constraint base property access
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
declare class ZodType<T> {
_output: T;
}
declare class ZodObject<Shape, Output> extends ZodType<Output> {
_shape: Shape;
}
type inferType<T extends ZodType<any>> = T["_output"];
interface ToolSpecifier {
name: string;
description: string;
run: (params: never) => Promise<string>;
}
type ToolParameters<T extends ToolSpecifier> = Parameters<T["run"]>[0];
export type AgentToolDefaultSchema = ZodObject<any, any>;
export interface AgentToolBase<
S extends AgentToolDefaultSchema = AgentToolDefaultSchema,
> {
name: string;
description: string;
inputSchema: S;
}
type AgentToolCallback<
S extends AgentToolDefaultSchema = AgentToolDefaultSchema,
> = (args: inferType<S>) => Promise<any>;
export interface AgentTool<
S extends AgentToolDefaultSchema = AgentToolDefaultSchema,
> extends AgentToolBase<S> {
run: AgentToolCallback<S>;
}
type AgentToolDescription<S extends AgentToolDefaultSchema> = {
name: string;
description: string;
schema: S;
run: AgentToolCallback<S>;
};
declare function agentTool<
S extends AgentToolDefaultSchema = AgentToolDefaultSchema,
>({ name, description, schema, run }: AgentToolDescription<S>): AgentTool<S>;
export function analysisTool<
T extends ToolSpecifier,
S extends ZodObject<any, ToolParameters<T>>,
>(t: T, schema: S) {
const { name, description } = t;
return agentTool({
name,
description,
schema,
run: async (params) => {
if ("point" in params && typeof params.point === "string") {
params = {
...params,
};
}
return await t.run(params);
},
});
}
π Actual behavior
Property 'point' does not exist on type 'inferType<S> & Record<"point", unknown>'.(2339)
π Expected behavior
This should be allowed or a better error should be reported
Additional information about the issue
This stems from inconsistent treatment of never
:
declare const test: never;
if ("foo" in test) { // ok
}
test.foo; // error
test["foo"]; // ok
const { foo } = test; // ok
but given this whole thing happens at generic level it's not even apparent to the user they deal with a type parameter that has a never
base constraint and that this might be the reason behind this confusing error
Metadata
Metadata
Assignees
Labels
No labels