Typing issue with nested class variables
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
If I have:
type InnerTest = {
aProp: number
}
type OuterTest = {
inner: InnerTest
}
const o: OuterTest = {
inner: {
aProp: 5
}
};
await sql `INSERT INTO some_table ${this.db(o)}`
Everything works fine.
If I change OuterTest to a class instead of a type, it still works.
But, If I change InnerTest to a class instead of a type, I get:
No overload matches this call.
Overload 1 of 2, '(first: OuterTest & Partial<Record<"inner", ParameterOrJSON<never>> & Record<string, any>>): Helper<OuterTest, []>', gave the following error.
Argument of type 'OuterTest' is not assignable to parameter of type 'OuterTest & Partial<Record<"inner", ParameterOrJSON<never>> & Record<string, any>>'.
Type 'OuterTest' is not assignable to type 'Partial<Record<"inner", ParameterOrJSON<never>> & Record<string, any>>'.
Types of property 'inner' are incompatible.
Type 'InnerTest' is not assignable to type 'ParameterOrJSON<never>'.
Type 'InnerTest' is not assignable to type '{ readonly [prop: string]: JSONValue | ((...args: any) => any); readonly [prop: number]: JSONValue | ((...args: any) => any); }'.
Index signature for type 'string' is missing in type 'InnerTest'.
Overload 2 of 2, '(template: TemplateStringsArray, ...parameters: readonly ParameterOrFragment<never>[]): PendingQuery<Row[]>', gave the following error.
Argument of type 'OuterTest' is not assignable to parameter of type 'TemplateStringsArray'.
Type 'OuterTest' is missing the following properties from type 'TemplateStringsArray': raw, length, concat, join, and 21 more.ts(2769)
const o: OuterTest
No quick fixes available
The only workaround seems to be to coerce sql to type any instead of postgres.Sql<{}>, but I'm not sure the consequences of that. It seems to basically turn off any type checking altogether.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the sql tagged-template call and the postgres.Sql<{}> typing shown in the report. Reproduce the nested-class case, then compare it with the working type-alias and outer-class cases to trace the incompatible ParameterOrJSON inference. Done means the class-based nested value is accepted without coercing sql to any while preserving type checking.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- databases, developer-experience
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100