Answer the question
In order to leave comments, you need to log in
Why is TypeScript not inferring the type correctly?
There is a request through the prisma library that returns a value with the User[] type. Why do I get a variable of type User and not User when I get element with index 0 from this array | undefined? The array can be empty.
Answer the question
In order to leave comments, you need to log in
Because, in fact, under the hood is this type:
type Array<T> = {
length: number;
[i: number]: T;
} & ArrayMethods<T>;
where ArrayMethods is the description of the methods from the prototype
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question