Skip to content

Additional solution for 085 #56

@optimizasean

Description

@optimizasean
interface Scores extends Record<string, number> {
  math: number;
  english: number;
  science: number;
}

// @ts-expect-error science is missing!
const scores: Scores = {
  math: 95,
  english: 90,
};

scores.athletics = 100;
scores.french = 75;
scores.spanish = 70;

I extended Record (but then realized it was a type alias, not an interface...and it worked!). Thought it was interesting to discover and might be worth adding in to 085 as another alternate solution since this seems to be a modern TypeScript pattern people take advantage of.

Not sure if this comes up later in a different module (only halfway through so far)!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions