You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
any is assignable to anything, so I don't really know what you could expect otherwise. We do have special a pre-pass for overload resolution where we try to resolve using subtyping instead of assignability, so you could add an overload to "catch" the any behavior first
declareletobj: {get(): Promise<ParsedResponseBody>get(rawResponse: false): Promise<ParsedResponseBody>get(rawResponse: true): Promise<RawResponse>// Should throw at runtime, can never return.get(rawResponse: any): never};
But really, I think you should avoid relying on this behavior. The real solution is to avoid using any when you can.
Hmm, I was trying to illustrate this situation, but I went too broad:
function ex(raw : boolean) {
// type error - "Argument of type 'boolean' is not assignable to parameter of type 'true'."
obj.get(raw).then(x => x)
}
not any but a boolean that we don't know is either true or false. This being an error is an improvement over the unsafe assumption I thought at first. But couldn't the checker do better here?
v2.6.2
Overload resolution makes an unsafe assumption when the type of the parameter is unknowable:
The text was updated successfully, but these errors were encountered: