You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Different inference behavior between method and function syntax as opposed to arrow functions. #38623
Personally I don't think this is a bug but rather an improvement.
A method signature will contextually type the object literal itself because this in method is the containing object literal. But an arrow function does not have this.
A user-side fix would be annotate this explicitly:
Activity
HerringtonDarkholme commentedon Aug 3, 2020
Personally I don't think this is a bug but rather an improvement.
A method signature will contextually type the object literal itself because
thisin method is the containing object literal. But an arrow function does not havethis.A user-side fix would be annotate
thisexplicitly:However, we can skip the contextual typing if
thisisn't accessed in the method.https://www.typescriptlang.org/play/?ts=4.0.0-dev.20200516#code/GYVwdgxgLglg9mABAWwIYGsCmAeAsgPgAo4AuRAbxRClVgQGczcAaRRVaeMMw5JgSkQBefIgBucGABNEAX0GVZAWABQqtFkLlVbKjTphGFHbt3A4cQlAAWMI+HRg4AdzAK5iAPSfEAeXQmcsyBHAY8qIIiFOwAdOaWgsoq8kA
test(types): add prop validator test
test(types): add prop validator test (#1769)