Closed
Description
TypeScript Version:
2.8.3
2.9.0-rc
3.0.0-dev.20180522
Search Terms:
true as true
Code
interface Good {
ok: true,
data: string,
}
interface Bad {
ok: false,
}
type Result = Good | Bad;
function convertPromiseDoesntCompile(p: Promise<string>): Promise<Result> {
return p.then(
(data: string) => ({ ok: true, data }),
() => ({ ok: false })
);
}
function convertPromiseCompiles(p: Promise<string>): Promise<Result> {
return p.then(
(data: string) => ({ ok: true as true, data }),
() => ({ ok: false as false})
);
}
Expected behavior:
Compiles without the uselessly looking casts
Actual behavior:
Type 'Promise<{ ok: boolean; data: string; } | { ok: boolean; }>' is not assignable to type 'Promise<Result>'.
Type '{ ok: boolean; data: string; } | { ok: boolean; }' is not assignable to type 'Result'.
Type '{ ok: boolean; data: string; }' is not assignable to type 'Result'.
Type '{ ok: boolean; data: string; }' is not assignable to type 'Bad'.
Types of property 'ok' are incompatible.
Type 'boolean' is not assignable to type 'false'.
Playground Link:
Related Issues: