Skip to content

Conversation

@markwpearce
Copy link
Collaborator

@markwpearce markwpearce commented Dec 15, 2025

Adds IntersectionType modelled after TypeScript's intersection types

  • Add IntersectionType
  • Add parsing for <type> and <type>
  • Allow "Grouped types" in parser (eg: (type1 or type2) and (type3 or type4))
  • Update type compatibility and other helpers to work with intersection types
  • Verify scope validation
  • Use order of operations on types, eg. type foo = myType1 or myType2 and myType3 or myType4 => myType1 or (myType2 and myType3) or myType4
  • Make sure type MyKlassAA = MyKlass and roAssociativeArray works properly
  • Add docs

}
let rightParen = this.advance();

let rightParen = this.consume(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been a bug a for a while? If the token was not ) it would just assume it was. :)

expressionsWithOperator.push({ expression: expr });

// handle expressions with order of operations - first "and", then "or"
const combineExpressions = (opToken: TokenKind) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially there is a better way of doing this...

This algorithm just gets a list of <type> <operator?>, and then first loops through it to combine all ands into binary expressions, then again to combine all ors

if (this.match(TokenKind.LeftCurlyBrace)) {
expr = this.inlineInterface();
} else if (this.match(TokenKind.LeftParen)) {
let left = this.previous();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type expression is a GroupingExpxression, eg. (integer or float)

getSymbolType: (innerName: string, innerOptions: GetTypeOptions) => {
const referenceTypeInnerMemberTypes = this.getMemberTypeFromInnerTypes(name, options);
if (!innerTypesMemberTypes || innerTypesMemberTypes.includes(undefined)) {
if (!referenceTypeInnerMemberTypes || referenceTypeInnerMemberTypes.includes(undefined)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes typo in code.. fixed an issue, but I can't remember exactly what ...

}
return this.isTypeCompatible(targetType) && targetType.isTypeCompatible(this);

if (this.types.length !== targetType.types.length) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More exact check for wquality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants