-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
isObject()
asserts untrue types
#12253
Comments
This issue is following up on #12250 |
It's imo obvious that the function cannot assert that the input type is actually of type used for the generic parameter. The parameter is there to keep the code more concise and help devs with code completion compared to just |
Hmh...that's sacrificing type safety for convenience. Not something I'm in favor of, in general. Could we assert |
Yeah, returning |
interface MyType {
foo: string
}
const unknownValue: unknown = { foo: 2 };
if (isObject<MyType>(unknownValue)) {
// We made it to this branch, and `unknownValue` now looks like:
// `{ foo?: string }` but `unknownValue.foo` is currently a number.
} I opened a PR with the most sane type we might be able to use instead. |
Bug Description:
in core/common/types.ts, we have the following code:
Let's say we have an interface like so:
Now if we do this:
Note that we don't get a compile problem, since inside the if,
someObject
is typed as aMyInterface
, but we get a runtime error, since the VM frowns upon callingtoString()
onundefined
.The text was updated successfully, but these errors were encountered: