Open
Description
TypeScript Version: 2.7.0-dev.201xxxxx
Code
// An object to hold all the possible options
type AllOptions = {
startDate: Date
endDate: Date
author: number
}
// Any combination of startDate, endDate can be used
type DateOptions =
| Pick<AllOptions, 'startDate'>
| Pick<AllOptions, 'endDate'>
| Pick<AllOptions, 'startDate' | 'endDate'>
type AuthorOptions = Pick<AllOptions, 'author'>
type AllowedOptions = DateOptions | AuthorOptions
const options: AllowedOptions = {
startDate: new Date(),
author: 1
}
Expected behavior:
An error that options
cannot be coerced into type AllowedOptions
because startDate
and author
cannot appear in the same object.
Actual behavior:
It compiles fine.