microsoft / microsoft/TypeScript

Type variables in TypedPropertyDescriptor cause compilation errors when using decorator

オープン
#33,405 コメント 3 件 リアクション 0 件 担当者 1 名 GitHub で見る

@rbuckton がすでに取り組んでいます。

2019年9月17日 から。

Needs Investigation
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

TypeScript Version: 3.6.3

Search Terms: TypedPropertyDescriptor, MethodDecorator, TS2345, Types of property 'value' are incompatible.

Code

type MyDynamicDescriptor = <T>(input: T) => T
type MyStaticDescriptor = (input: number) => number

function dynamicDecorator(foo: string) {
  return (_: any, __: any, descriptor: TypedPropertyDescriptor<MyDynamicDescriptor>) => {
    console.log('foo:', foo)
    console.log('descriptor.value:', descriptor.value)
  }
}

function staticDecorator(foo: string) {
  return (_: any, __: any, descriptor: TypedPropertyDescriptor<MyStaticDescriptor>) => {
    console.log('foo:', foo)
    console.log('descriptor.value:', descriptor.value)
  }
}

class myClass {
  @dynamicDecorator('bar')
  myMethod(input: number): number {
    return input + 42
  }

  @staticDecorator('bar')
  myOtherMethod(input: number): number {
    return input + 42
  }
}

Expected behavior:
No compilation errors for both dynamicDecorator and staticDecorator.

Actual behavior:
Compilation errors for dynamicDecorator:

error TS2345: Argument of type 'TypedPropertyDescriptor<(input: number) => Promise<number>>' is not assignable to parameter of type 'TypedPropertyDescriptor<MyDynamicDescriptor>'.
  Types of property 'value' are incompatible.
    Type '((input: number) => Promise<number>) | undefined' is not assignable to type 'MyDynamicDescriptor | undefined'.
      Type '(input: number) => Promise<number>' is not assignable to type 'MyDynamicDescriptor'.

Playground Link

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。