Skip to content

Allow stricter structural typing #391

Closed
@jbrantly

Description

@jbrantly

Say I have the following:

interface Options {
    doSomethingSpecial?: boolean
}

function configure(options: Options) {}
configure({});

The preceding (correctly) does not flag any issues. However, say I change the function call to:

configure({doSomethingSuper: true});

This also does not flag any issues. I understand that in many (most?) cases this is the desired behavior, but in other cases it seems that a stricter matching (ie, you don't have to specify "doSomethingSpecial" but you can't specify anything else either) would be desirable. There are at least two instances that I can think of where this applies:

  1. Catching typos
  2. (more importantly) Compile-time checking after a refactoring of "doSomethingSpecial" to be named something else

Perhaps some new syntax for enabling this mode would be useful. For example:

function configure(options: Options!) {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking ChangeWould introduce errors in existing codeCommittedThe team has roadmapped this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions