-
-
Notifications
You must be signed in to change notification settings - Fork 152
Description
🍩 Feature Request
Is your feature request related to a problem?
It would be great to have an exact object / interface utility type as a part of ts-toolbelt - preventing any fewer properties or excess properties passed in an object - such as:
function fn(arg: Exact<{ x: string }>) {}
// ok
fn({ x: '' });
// errors
fn({ y: '' });
fn({ x: '', y: '' });This is one of the top-requested features in TypeScript itself, but does not yet exist in the language.
Describe the solution you'd like
A new exported Object/Exact utility type to allow for checking against exact types
Describe alternatives you've considered
I saw Function/Exact, but this appears to be something different... This docs page does use some of the same words when describing the problem, which at first seems to indicate it's the right thing:
Force
Ato comply withW.Amust be a shape ofW. In other words,Amust extendWand have the same properties - no more, no less.
...but I don't understand how / where I would apply this Exact<A, W> generic signature. 🤔
Teachability, Documentation, Adoption, Migration Strategy
For implementation of the utility, some of the answers in the TypeScript issue are potentially useful:
- Exact Types microsoft/TypeScript#12936 (comment)
- Exact Types microsoft/TypeScript#12936 (comment)
- Exact Types microsoft/TypeScript#12936 (comment)
The code block in the first section above could be used an example in the docs for the type.