microsoft / microsoft/TypeScript

PropertyDecorator factory with generic type is not so intelligent

Open
#31,917 1 comment 0 reactions 1 assignee View on GitHub

@rbuckton is already working on this.

Since Jun 26, 2019.

Needs Investigation
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.5.1

Search Terms:

Code

export const Reactive = <T, K extends keyof T>(
  setter?: (this: T, value?: T[K]) => boolean | void,
) => (target: T, propertyKey: K) => {
  // do something
};

class Test {
  @Reactive(function(name) {
    // error
  })
  name: string
}

Expected behavior:
Automatically detect this should be type of Test, and name should be type of string

Actual behavior:
Argument of type '"name"' is not assignable to parameter of type 'never'.

Playground Link:
Playground Link

Related Issues:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.