Steps to reproduce
- Clone repo https://github.com/jansedlon/tsgo-repro
- Install dependencies
- Open index.ts
Behavior with typescript@5.9
The constant posts has a type of
const posts: {
id: string;
createdAt: Date;
updatedAt: Date;
}[]
And typescript reports error in attachments object because selecting database fields needs to be inside of columns object and orderBy in attachments like so
attachments: {
columns: {
id: true,
// ...
},
orderBy(fields, { asc }) {
return asc(fields.createdAt);
}
}
Behavior with tsgo
Not only it doesn't report any error, it even considers wrong API usage as correct and infers types. This would result in runtime error.
The type of posts is inferred as
const posts: {
attachments: {
createdAt: Date;
filename: string | null;
id: string;
location: string;
postId: string | null;
size: number | null;
type: string;
updatedAt: Date;
}[];
id: string;
}[]
Note
I have found out that the thing that breaks this is the orderBy function. If you comment that out, it will start reporting errors.
Steps to reproduce
Behavior with
typescript@5.9The constant
postshas a type ofAnd typescript reports error in
attachmentsobject because selecting database fields needs to be inside ofcolumnsobject andorderByinattachmentslike soBehavior with
tsgoNot only it doesn't report any error, it even considers wrong API usage as correct and infers types. This would result in runtime error.
The type of
postsis inferred asNote
I have found out that the thing that breaks this is the
orderByfunction. If you comment that out, it will start reporting errors.