Skip to content

this function type shifts the argument index in the argument decorators #29427

@capaj

Description

@capaj

TypeScript Version: 3.3.0-dev.201xxxxx

Search Terms: decorator this

Code

const dec = function(target, field, argIndex) {
 console.log(target, field, argIndex) // outputs {constructor: ƒ, test: ƒ} "test" 1
}

class A {
    test(this: any, @dec a) {
        console.log(a) 
    }
}

I believe it should be ignored when decorators are used within a function with explicitly typed this(#6739 )

Expected behavior:
expects argIndex index to be 0
Actual behavior:
argIndex index in the decorator is 1

Playground Link: https://typescript-play.js.org/?noImplicitAny=false&strictNullChecks=false&experimentalDecorators=true&emitDecoratorMetadata=true#code/MYewdgzgLgBAtgUwhAhgcwQLhtATgSzDRgF4YByACwQBsaQYB3EXGgE3IG4Aob0SWGwTBSMAGYBXMMCj5wACigpcGKABpx+Wmw3K0ASTBCAHgEoYAb24x+EEDQQA6emkV6E6zdt0rDJ09wAvrzANCjIMACCltYwcVBIUIqU+BDYKGAAnhoAAkIiKOZWcSUltvZOLvKFsXHBwdxAA

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions