Skip to content
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

[Feature] Implement in expression which checks if a given key exists in the provided type #707

Open
2 of 4 tasks
Luna-Klatzer opened this issue Sep 25, 2024 · 0 comments
Open
2 of 4 tasks
Assignees
Labels
feature New feature or enhancement
Milestone

Comments

@Luna-Klatzer
Copy link
Member

Luna-Klatzer commented Sep 25, 2024

Is there an existing proposal for this?

  • I have searched the existing issues

This feature does not exist in the latest version

  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or enhancement
Projects
Development

No branches or pull requests

1 participant