Kipper
Kipper copied to clipboard
[Feature] Implement `in` expression which checks if a given key exists in the provided type
Is there an existing proposal for this?
- [X] I have searched the existing issues
This feature does not exist in the latest version
- [X] I am using the latest version
Proposal
Implement KEY in REF
expression, which checks if a given key is present in the provided reference. The behaviour will be identical to the JavaScript in
expression.
As Kipper is strongly typed, the compiler should be able to recognise that a type has been narrowed down in a specific branch of an if-statement or conditional expression. See #705 for more info on that.
For example:
interface X {
x: num;
y: num;
}
var x: X = {
x: 1,
y: 2,
z: 3,
};
if ("z" in X) {
// -> x: X & { z: any }
...
}
Exact behaviour / changes you want
- [ ] Implement support for the
in
expression which allows custom key type checks. - [ ] Implement proper translation for the
in
keyword to JavaScript and TypeScript.
Related issues
- #705
- #706