Skip to content

Add support for typed associative array values #1633

@luis-j-soares

Description

@luis-j-soares

This is likely too close to Generics support, but we could use some way to type the values of AAs without being concerned for its keys.

Typescript does it with mapped types:

type OnlyBoolsAndHorses = {
  [key: string]: boolean | Horse;
};
 
const conforms: OnlyBoolsAndHorses = {
  del: true,
  rodney: false,
};

Originally, given that our AAs support nothing other than strings, I was going to suggest adding some sort of Map<T> syntax. However, I started thinking about how we could use string-based enums for keys as well. So I'm wondering how we could make it neater. Perhaps the same syntax as Typescript could work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    New Language FeatureA proposal for a new feature to be added to the BrighterScript languageenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions