-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Description
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
union type
bug
Code
class Package {
public name: string;
public isDev?: boolean;
}
interface Devable extends Package {
devOnly: false;
}
interface DevOnlyPackage extends Package {
isDev?: true;
devOnly: true;
}
// This should throw an error.
const d: Package | Devable | DevOnlyPackage = {
name: "yarn",
isDev: false,
devOnly: true,
};Expected behavior:
The annotation on const d should throw an error. It can't be a Package because it has additional fields, it can't be Devable because devOnly is false, and it can't be DevOnlyPackage because isDev is false.
Actual behavior:
No error is thrown.
Playground Link: playground
If you try to assert each type individually, it will throw an error as expected, but when a union type is used, it passes the check.
Related Issues:
Metadata
Metadata
Assignees
Labels
No labels