-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Generic type is being ignored #26639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In |
wow this is so non obvious, thanks for the answer |
@pleerock Could you post a small complete example as plaintext that I could use to verify? |
@Andy-MS there you are: export class Model<ModelType> {
__nominal!: ModelType;
constructor(name: string) {
}
}
export interface Category {
id: number;
name: string;
posts?: Post[];
}
export interface Post {
id: number;
title: string;
categories: Category;
}
export const PostModel = new Model<Post>("Post");
export const CategoryModel = new Model<Category>("Category");
export type ResolverOptions<ModelType> = {
[P in keyof ModelType]?: { type: Model<ModelType[P]> }
}
export function resolver<ModelType>(
model: Model<ModelType>,
resolver: ResolverOptions<ModelType>
) {
}
export const PostResolver = resolver(PostModel, {
categories: {
// test autocompletion here
}
}); |
Ah, that's because |
Last line (
type: PostModel
) should give an error.It does know what type to expect right:
However it accepts any instance of Model - PostModel, CategoryModel, PhotoModel without any error. Why?
p.s. sorry for the bad title, hope somebody can help to name this issue properly
The text was updated successfully, but these errors were encountered: