Skip to content

Use safer type annotations #88

@Noam-Bendelac

Description

@Noam-Bendelac

Primarily in playlists.ts, I'm using type annotations like

{
  action: 'comment',
  message,
  timestamp: new Date(),
  userId: res.locals.userId,
} as SituatedChatEvent

For auto-completion convenience, however this is very unsafe as a property could be missing and typescript would not give me an error (similar to the problems in microsoft/TypeScript#7481 (comment) and that issue in general). It seems the best way to fix this is either to move expressions like this into a temporary variable with a variable: Type annotation, or wrap the expressions in a util function like

function asType<T>(value: T) {
  return value;
};

As suggested in the linked issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendBackend functionalitybugSomething isn't workingfrontendFrontend functionality

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions