Microsoft/TypeScript

Contextual inference for nested calls that return constructors

Open

#57,747 建立於 2024年3月12日

在 GitHub 查看
 (2 留言) (0 反應) (0 負責人)TypeScript (6,726 fork)batch import
Domain: check: Type InferenceHelp WantedPossible Improvement

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

#54813 attempted to make this work, but exposed an underlying bug that caused too many instantiations. Once that bug is fixed, the code in #54813 should be re-applied if possible.

Here's an example of something that should work, but doesn't:

// @strict: true
// @noEmit: true

interface Action<TContext> {
  new (ctx: TContext): void;
}

declare class AssignAction<TContext> {
  constructor(ctx: TContext);
}

declare function assign<TContext>(
  assigner: (ctx: TContext) => void
): {
  new (ctx: TContext): AssignAction<TContext>;
}

declare function createMachine<TContext>(config: {
  context: TContext;
  entry: Action<TContext>;
}): void;

createMachine({
  context: { count: 0 },
  entry: assign((ctx) => { ctx }),
});

ctx should have type { count: number }, inferred from the context of assign, but doesn't.

貢獻者指南