Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Make tuple and custom array declared as interface compatible #216

@kdy1

Description

@kdy1

Problem

interface StrNum extends Array<string|number> {
0: string;
1: number;
length: 2;
}

This type is treated almost as a tuple by tsc, but stc fails to verify it.
It's because it extends Array.

image

Solution

I think we should handle it from Analyzer.normalize.
Implementing special rules to each function for handling such edge looks like overengineering.

We can add logic for checking if the ty is an interface which extends an array-like builtin interface at

match ty.normalize() {
Type::Lit(..)
| Type::TypeLit(..)
| Type::Interface(..)
| Type::Class(..)
| Type::ClassDef(..)
| Type::Tuple(..)
| Type::Function(..)
| Type::Constructor(..)
| Type::EnumVariant(..)
| Type::Enum(..)
| Type::Param(_)
| Type::Module(_)
| Type::Tpl(..) => return Ok(ty),
_ => {}
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomers

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions