microsoft / microsoft/tslib

tslib __decorate was conflict with property decorator definition

Open
#46 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.3k
Forks
145
PR merge metrics
No merged PRs in 30d

Description

such a code with property decorator usage:

class Controller {

	name = 'xx';

	@inject(Store)
	store: any = null;
}

after a tsc compiling:

var Controller = /** @class */ (function () {
        function Controller() {
            this.name = 'xx';
            this.store = null;
        }
        tslib_1.__decorate([
            inject_1.default(Store)
        ], Controller.prototype, "store", void 0);
        return Controller;
    }());

and here is the tslib __decorate implementation:
https://github.com/Microsoft/tslib/blob/b1ed5e1b940756d18609833caf9b781e9bc3984f/tslib.js#L85-L90
we can realize that if the property decorator return a descriptor, __decorate function will define property for us, from the code above.

but in typescript lib.es.d.ts definition, property decorator should not return anything:
https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es6.d.ts#L1285

declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;

so which one is the truth?

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Compare the __decorate implementation in tslib.js at the linked lines with the PropertyDecorator definition in TypeScript's lib/lib.es6.d.ts and the generated example in the issue. Determine whether the runtime behavior and type definition should agree, then document the expected behavior or identify the necessary change and its validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.