TypeScript Version: 3.1.1
Search Terms: unions
Code
export enum ButtonStatus {
ENABLED = 'enabled',
DISABLED = 'disabled',
LOADING = 'loading',
}
export interface RegularButtonProps {
readonly status: ButtonStatus;
}
export interface LoadingButtonProps {
readonly status: ButtonStatus.LOADING;
readonly loadingText: string;
}
export type ButtonProps = RegularButtonProps | LoadingButtonProps;
const buttonProps: ButtonProps = {
status: ButtonStatus.LOADING,
loadingText: 42,
};
Expected behavior:
Error saying loadingText should be of type string.
Actual behavior:
No error. Hovering over loadingText does tell me that loadingText is a string, so the compiler knows but doesn't raise it?

Playground Link:
https://www.typescriptlang.org/play/#src=export%20enum%20ButtonStatus%20%7B%0A%20%20ENABLED%20%3D%20'enabled'%2C%0A%20%20DISABLED%20%3D%20'disabled'%2C%0A%20%20LOADING%20%3D%20'loading'%2C%0A%7D%0A%0Aexport%20interface%20RegularButtonProps%20%7B%0A%20%20readonly%20status%3A%20ButtonStatus%3B%0A%7D%0A%0Aexport%20interface%20LoadingButtonProps%20%7B%0A%20%20readonly%20status%3A%20ButtonStatus.LOADING%3B%0A%20%20readonly%20loadingText%3A%20string%3B%0A%7D%0A%0Aexport%20type%20ButtonProps%20%3D%20RegularButtonProps%20%7C%20LoadingButtonProps%3B%0A%0Aconst%20buttonProps%3A%20ButtonProps%20%3D%20%7B%0A%20%20status%3A%20ButtonStatus.LOADING%2C%0A%20%20loadingText%3A%2042%2C%0A%7D%3B%0A
Related Issues:
Mmmaybe this one? #26450
TypeScript Version: 3.1.1
Search Terms: unions
Code
Expected behavior:
Error saying
loadingTextshould be of typestring.Actual behavior:
No error. Hovering over
loadingTextdoes tell me thatloadingTextis a string, so the compiler knows but doesn't raise it?Playground Link:
https://www.typescriptlang.org/play/#src=export%20enum%20ButtonStatus%20%7B%0A%20%20ENABLED%20%3D%20'enabled'%2C%0A%20%20DISABLED%20%3D%20'disabled'%2C%0A%20%20LOADING%20%3D%20'loading'%2C%0A%7D%0A%0Aexport%20interface%20RegularButtonProps%20%7B%0A%20%20readonly%20status%3A%20ButtonStatus%3B%0A%7D%0A%0Aexport%20interface%20LoadingButtonProps%20%7B%0A%20%20readonly%20status%3A%20ButtonStatus.LOADING%3B%0A%20%20readonly%20loadingText%3A%20string%3B%0A%7D%0A%0Aexport%20type%20ButtonProps%20%3D%20RegularButtonProps%20%7C%20LoadingButtonProps%3B%0A%0Aconst%20buttonProps%3A%20ButtonProps%20%3D%20%7B%0A%20%20status%3A%20ButtonStatus.LOADING%2C%0A%20%20loadingText%3A%2042%2C%0A%7D%3B%0A
Related Issues:
Mmmaybe this one? #26450