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 syntax- and type-support for objects and syntax for user-defined interfaces #284

Open
2 of 11 tasks
Luna-Klatzer opened this issue Aug 12, 2022 · 0 comments
Assignees
Labels
feature New feature or enhancement
Milestone

Comments

@Luna-Klatzer
Copy link
Member

Luna-Klatzer commented Aug 12, 2022

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 TypeScript-like objects and interfaces, which should allow the user definition of objects and the creation of custom Kipper object types (interfaces). These types though should unlike in TypeScript be also available at runtime time in form of an object of type type.

This object should store the relevant metadata of the interface type and be defined once during the creation of the interface.

Interfaces though should primarily be used to define blueprints for objects during compile-time type checking, where each field of an interface must be implemented in an object to meet the interface type criteria e.g. be effectively of that type. These interfaces can then be used as types on variables or arguments as the basic blueprint, where only objects matching the interface can be stored.

For example:

interface Blueprint {
  field: num;
}

// Valid
var obj1: Blueprint = { field: 1; };

// Invalid - Does not meet requirements of interface
var obj2: Blueprint = { };
var obj3: Blueprint = { x: "1"; }

// Invalid - Type 'str' does not meet type 'num' of field 'field'
var obj4: Blueprint = { field: "2"; }

Here though interfaces will not be fully strict and use duck-typing like in TypeScript to check whether an object matches an interface. This means additional fields not specified by the interface can be present in the object, while still correctly matching the type criteria of the interface.

For example:

// Valid
var obj5: Blueprint = { field: 1, anotherField: 2, ... };

Exact behaviour / changes you want

  • [Feature] Implement dot notation member-access syntax parent.field #67
  • Implement constant object syntax using curly brackets, where an object can be defined with its fields. Same behaviour and syntax with JS object definitions.
  • Implement syntax support for interfaces using the interface ... { ... } syntax.
  • Implement semantic analysis for the interface, where the following primary issues should be checked:
    • Field definitions are only done once and identifiers may not be duplicated.
    • Field definitions may not overwrite built-in or reserved identifiers.
  • Implement type checking for the interface type and variables of that type, where child fields of the type should be properly determined and usable.
  • Implement translation of the objects and interfaces in the JS and TS target.
  • Implement translation of the runtime interface type (Implementation details in work...)
@Luna-Klatzer Luna-Klatzer added the feature New feature or enhancement label Aug 12, 2022
@Luna-Klatzer Luna-Klatzer added this to the Stable Kipper Release milestone Aug 12, 2022
@Luna-Klatzer Luna-Klatzer self-assigned this Aug 12, 2022
@Luna-Klatzer Luna-Klatzer changed the title [Feature] Implement type-support for objects and custom user-defined interfaces [Feature] Implement syntax- and type-support for objects and syntax for user-defined interfaces Aug 15, 2022
@Luna-Klatzer Luna-Klatzer modified the milestones: Stable Kipper Release, v0.11.0 Jan 28, 2023
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
Status: Under Consideration
Development

No branches or pull requests

1 participant