Skip to content

difference in typecheck with 5.8 (broken type inference) #798

@dartess

Description

@dartess

Same errors, locations, and messages as TS5.8

I got 2 "new" errors on my huge project. I consider it an incredible luck, but I think I should report on the remaining two. here is the first one:

(This is the minimum example I could reproduce with the original error. As soon as I simplify it more I either get another error or they disappear)

type Message = { options?: Record<string, unknown> };

type Shared<T> = { handler: (message: T) => void };
type Static<T> = Shared<T> & { message: T };
type Dynamic<T> = Shared<T> & { message: () => T };

declare function subscribe<TMessage extends Message>(
  payload: (Dynamic<TMessage> | Static<TMessage>) & {},
): void;

subscribe({
  message: () => ({
    options: { market: '' },
  }),
  handler: (message) => message.options.market,
});

export {};
error TS18048: 'message.options' is possibly 'undefined'.

15   handler: (message) => message.options.market,

TS 5.8.3 is fine with this: playground

The easiest way to "fix" this error is to remove the intersection & {} (but in my code there is a type with some fields and I can't)

Metadata

Metadata

Assignees

Labels

Domain: Type CheckingRelated to type checking, grammar checkingType OrderingAn issue related to ordering of types

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions