Closed
Description
TypeScript Version: 4.1.0-dev.20200819
Search Terms: unknown inference string
Code
declare const thrownError: { code?: unknown; }
const thrownErrorCode = thrownError?.code && String(thrownError.code);
const str: string | undefined = thrownErrorCode;
Expected behavior: No Error
Actual behavior:
Error: Type 'unknown' is not assignable to type 'string'.(2322) in the last line.
Playground Link:
Working version with 4.1.0-dev.20200818:
EDIT: Added missing | undefined