Skip to content

Ways to seal objects, even at instantiation? #1164

@STRML

Description

@STRML

We use objects often as a way to pass many parameters to remoting functions.

We'd like to very strictly typecheck these objects, but it appears we're unable to properly seal the objects in the type definitions. For example, we want the following code to fail:

type GetTableParams = {table: string, optionalProperty?: number};
db.getTable = (params: GetTableParams): Promise<Array<Object>> {
  ...
}

// This should throw an error
db.getTable({table: 'foo', anInvalidProperty: 'bar'});

Is there a way to signify that an object type should have only the properties in the typedef and nothing more?

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