-
-
Notifications
You must be signed in to change notification settings - Fork 669
Support non-null assertion expression x!
#235
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
Conversation
cc @MaxGraey |
Great! We also discussed with @dcodeIO about new semantic meaning of exclamation operator for array's unchecked index access like write btw @andy-hanson you should have received an invitation to our Slack chat. |
LGTM, except this PR should also handle this case: class Foo { boo: i32 }
export function test2(foo: Foo | null): i32 {
return foo!.boo;
} Currently this fail |
Remains the question what we'll do with unchecked accesses then (what |
It is necessary to formalize how semantically an "unchecked case" will be handled in combination with non-null assertion. If you consider each case for array access, then you can get: 1). Array is non-nullable
2). Array is nullable
What do you think? |
Another variant for "unchecked" index access of array is |
Not a bad idea. That could work, on the index, as it should never be nullable anyway due to being an i32. |
See #233 -- IMO |
There are some occasions in the sources where a |
Sorry for not following up here. Wasn't quite comfortable with the implementation but couldn't tell why. Now implemented in #443 as another kind of assertion. Thank you anyway! |
Adds support for TypeScript's
x!
non-null assertion expression. Ifx
is of typeT | null
, this is equivalent to<T> x
.(Documentation: See "Type guards and type assertions" at in the TypeScript handbook)
This does not come with a runtime check for consistency with type assertions. See #234.