Allow stricter structural typing · Issue #391 · microsoft/TypeScript (original) (raw)
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:
- Catching typos
- (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!) {}