Closed
Description
Looks like similar issues have existed before, I'm getting an error where I can't assign the value true to a property with a type of true e.g, ComplicatedType | simpleType | { thisFieldShouldBeTrue: true }
.
TypeScript Version: 3.3.0-dev.20181218
Search Terms:
true is not assignable to type boolean
boolean is not assignable to type true
Code
function get<ServerEndpoint extends { endpoint: string, execute: (...args: any) => any } | null>(params: FirstArgument<ServerEndpoint["execute"]>): ReturnValue<ServerEndpoint["execute"]> | { error: any } | { pending: true } {
return {
pending: true,
};
}
type FirstArgument<T> = T extends (arg1: infer U, ...args: any[]) => any ? Partial<U> : any;
type ReturnValue<T extends (...args: any) => any> =
ReturnType<T> extends Promise<infer U> ? U :
ReturnType<T>;
Expected behavior:
Compile successfully
Actual behavior:
$> npx tsc reproduction.ts
reproduction.ts:2:3 - error TS2322: Type '{ pending: boolean; }' is not assignable to type 'ReturnValue<ServerEndpoint["execute"]> | { error: any; } | { pending: true; }'.
Type '{ pending: boolean; }' is not assignable to type '{ pending: true; }'.
Types of property 'pending' are incompatible.
Type 'boolean' is not assignable to type 'true'.
2 return {
~~~~~~~~
3 pending: true,
~~~~~~~~~~~~~~~~~~
4 };
~~~~
Found 1 error.