P
Prisma•2mo ago
ReDev1L

Property '[PrivateResultType]' is missing in type 'TypedSql<Parameters, Result>'

Error:
Argument of type 'TypedSql<Parameters, Result>' is not assignable to parameter of type 'TypedSql<unknown[], Result>'.
Property '[PrivateResultType]' is missing in type 'TypedSql<Parameters, Result>' but required in type 'TypedSql<unknown[], Result>'.ts(2345)
Argument of type 'TypedSql<Parameters, Result>' is not assignable to parameter of type 'TypedSql<unknown[], Result>'.
Property '[PrivateResultType]' is missing in type 'TypedSql<Parameters, Result>' but required in type 'TypedSql<unknown[], Result>'.ts(2345)
usage:
const usageByUser = await db.$queryRawTyped<getUsageByOrgId.Result>(
getUsageByOrgId(from, to, organizationId.toString())
)
const usageByUser = await db.$queryRawTyped<getUsageByOrgId.Result>(
getUsageByOrgId(from, to, organizationId.toString())
)
TypedSQL:
WITH RECURSIVE params(from_period, to_period, organizationId) AS (
SELECT ? AS from_period, ? AS to_period, ? AS organizationId
),

usage_stats AS (
SELECT
cu.id,
cu.email,
SUM(bpu.billable_seconds) as total_seconds,
SUM(CASE
WHEN bpu.created_at >= (SELECT from_period FROM params)
AND bpu.created_at <= (SELECT to_period FROM params)
THEN bpu.billable_seconds
ELSE 0
END) as period_minutes,
COUNT(DISTINCT bpu.session_id) as total_billed_sessions,
COUNT(DISTINCT CASE
WHEN bpu.created_at >= (SELECT from_period FROM params)
AND bpu.created_at <= (SELECT to_period FROM params)
THEN bpu.session_id
ELSE NULL
END) as period_billed_sessions
FROM billing_v2_product_usage bpu
JOIN copilot_user cu ON cu.id = bpu.user_id
JOIN copilot_organizationuser cou ON cou.user_id = cu.id AND cou.organization_id = (SELECT organizationId FROM params)
WHERE bpu.created_at >= cou.created_at
AND cu.id IN (
SELECT user_id
FROM copilot_organizationuser
WHERE organization_id = (SELECT organizationId FROM params)
)
GROUP BY cu.id, cu.email
)
SELECT
id,
email,
CASE WHEN total_seconds = 0 OR total_seconds IS NULL THEN 0 ELSE ROUND(total_seconds / 60) END AS total_minutes,
CASE WHEN period_minutes = 0 OR period_minutes IS NULL THEN 0 ELSE ROUND(period_minutes / 60) END AS period_minutes,
total_billed_sessions,
period_billed_sessions
FROM usage_stats
ORDER BY total_minutes DESC;
WITH RECURSIVE params(from_period, to_period, organizationId) AS (
SELECT ? AS from_period, ? AS to_period, ? AS organizationId
),

usage_stats AS (
SELECT
cu.id,
cu.email,
SUM(bpu.billable_seconds) as total_seconds,
SUM(CASE
WHEN bpu.created_at >= (SELECT from_period FROM params)
AND bpu.created_at <= (SELECT to_period FROM params)
THEN bpu.billable_seconds
ELSE 0
END) as period_minutes,
COUNT(DISTINCT bpu.session_id) as total_billed_sessions,
COUNT(DISTINCT CASE
WHEN bpu.created_at >= (SELECT from_period FROM params)
AND bpu.created_at <= (SELECT to_period FROM params)
THEN bpu.session_id
ELSE NULL
END) as period_billed_sessions
FROM billing_v2_product_usage bpu
JOIN copilot_user cu ON cu.id = bpu.user_id
JOIN copilot_organizationuser cou ON cou.user_id = cu.id AND cou.organization_id = (SELECT organizationId FROM params)
WHERE bpu.created_at >= cou.created_at
AND cu.id IN (
SELECT user_id
FROM copilot_organizationuser
WHERE organization_id = (SELECT organizationId FROM params)
)
GROUP BY cu.id, cu.email
)
SELECT
id,
email,
CASE WHEN total_seconds = 0 OR total_seconds IS NULL THEN 0 ELSE ROUND(total_seconds / 60) END AS total_minutes,
CASE WHEN period_minutes = 0 OR period_minutes IS NULL THEN 0 ELSE ROUND(period_minutes / 60) END AS period_minutes,
total_billed_sessions,
period_billed_sessions
FROM usage_stats
ORDER BY total_minutes DESC;
Generated types:
export const getUsageByOrgId: (from_period: Date, to_period: Date, organizationId: string) => $runtime.TypedSql<getUsageByOrgId.Parameters, getUsageByOrgId.Result>

export namespace getUsageByOrgId {
export type Parameters = [from_period: Date, to_period: Date, organizationId: string]
export type Result = {
id: bigint
email: string
total_minutes: $runtime.Decimal | null
period_minutes: $runtime.Decimal | null
total_billed_sessions: bigint
period_billed_sessions: bigint
}
}
export const getUsageByOrgId: (from_period: Date, to_period: Date, organizationId: string) => $runtime.TypedSql<getUsageByOrgId.Parameters, getUsageByOrgId.Result>

export namespace getUsageByOrgId {
export type Parameters = [from_period: Date, to_period: Date, organizationId: string]
export type Result = {
id: bigint
email: string
total_minutes: $runtime.Decimal | null
period_minutes: $runtime.Decimal | null
total_billed_sessions: bigint
period_billed_sessions: bigint
}
}
How to fix this error?
2 Replies
Prisma AI Help
Prisma AI Help•2mo ago
Skipping coffee for instant knowledge! Let's brew that AI answer now. To fix this error, you need to modify your usage of $queryRawTyped. The error occurs because the type parameter you're providing doesn't match the expected type of the getUsageByOrgId function. Here's how you can fix it:
const usageByUser = await db.$queryRawTyped(getUsageByOrgId(from, to, organizationId.toString()))
const usageByUser = await db.$queryRawTyped(getUsageByOrgId(from, to, organizationId.toString()))
By removing the explicit type parameter <getUsageByOrgId.Result>, you allow TypeScript to infer the correct type based on the return type of getUsageByOrgId. The reason for this error is that $queryRawTyped expects a TypedSql object, which is what getUsageByOrgId returns. By explicitly specifying only the Result type, you're creating a mismatch between the expected and provided types. This solution is based on the information provided in the Prisma blog post about TypedSQL, which shows the correct usage of TypedSQL queries. If you need to explicitly type the result, you can do so after the query:
const usageByUser = await db.$queryRawTyped(getUsageByOrgId(from, to, organizationId.toString())) as getUsageByOrgId.Result[]
const usageByUser = await db.$queryRawTyped(getUsageByOrgId(from, to, organizationId.toString())) as getUsageByOrgId.Result[]
Note that the result is an array of the Result type, hence the [] at the end. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
ReDev1L
ReDev1LOP•2mo ago
still error even if u remove type. this type has PrivateResultType symbol:
export declare class TypedSql<Values extends readonly unknown[], Result> {
[PrivateResultType]: Result;
constructor(sql: string, values: Values);
get sql(): string;
get values(): Values;
}
export declare class TypedSql<Values extends readonly unknown[], Result> {
[PrivateResultType]: Result;
constructor(sql: string, values: Values);
get sql(): string;
get values(): Values;
}

Did you find this page helpful?