Skip to content

Function adding property type errorΒ #55303

Closed as not planned
Closed as not planned
@zclsx

Description

@zclsx

πŸ”Ž Search Terms

Function addition attribute

πŸ•— Version & Regression Information

No solution is provided in typescript

⏯ Playground Link

No response

πŸ’» Code

interface ReactiveEffectRunner<T = any> {
  (): T;
  effect: ReactiveEffect;
}
  const runner = _effect.run.bind(_effect) as ReactiveEffectRunner;

  runner.effect = _effect;

πŸ™ Actual behavior

const runner:ReactiveEffectRunner = _effect.run.bind(_effect);

When we use type annotations this way, we get an error: type "() => Missing attribute "effect" in any" but type "ReactiveEffectRunner< any>" This property is required in.

πŸ™‚ Expected behavior

How do we assign properties to a function if we don't use as to make assertions?

I needed typescript to provide a solution for us to solve the problem of incorrect function assignment types, instead of using crude assertions to solve it. Because typescript can put forward solutions to solve problems, it will make the code more elegant. Looking forward to your reply, thank you! πŸ™

### Tasks

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions