Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PropertyDecorator factory with generic type is not so intelligent #31917

Open
JounQin opened this issue Jun 15, 2019 · 1 comment
Open

PropertyDecorator factory with generic type is not so intelligent #31917

JounQin opened this issue Jun 15, 2019 · 1 comment
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@JounQin
Copy link

JounQin commented Jun 15, 2019

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:

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jun 26, 2019
@aliechti
Copy link

Maybe this is the same Issue as I have.

I would expect that this would cry a river at @testProperty('shouldNotWork') but it doesn't:

function testProperty<T>(otherProperty: keyof T): PropertyDecorator {
    return (target, propertyKey) => {
        // ... some code
    };
}

class Test {
    @testProperty('shouldWork')
    test: boolean = true;
    @testProperty('shouldNotWork')
    test2: boolean = true;
    shouldWork: boolean = true;
}

My current workaround is to define the type manually like this:

class Test2 {
    @testProperty<Test2>('shouldWork')
    test: boolean = true;
    @testProperty<Test2>('shouldNotWork')
    test2: boolean = true;
    shouldWork: boolean = true;
}

https://www.typescriptlang.org/play/index.html?experimentalDecorators=true#code/GYVwdgxgLglg9mABFApgZygBQE5wA4rZQCeAPACoB8AFHFABaE76EkBciA1isXMIuQCUHZgSLEAIighxsAQyizEAbwCwAKERbE2FFBDYk1KHOwBzPQBpEeXGJIBpHoMQBeSio3bviAPS-EADpgxDQ4AFsURBkAExQvbQBfAG4NRI0NCAAbOTQ0AXQoT01tAAFUDFFWYmoAcjR6OBAsmIB1WU5awQStCqgOACM4OCyUOSRXZGwQFFSSrXLCqvE6hqaWgDk6duxO7vnkQoAmQeHR8bcpmbnvNea2jtORsYmr2bSM9Wzc-PJj4u8i0qdmqFGONHqjXuOz2PUOGCe51eUGm7wOQKwIPEYIwRwhd022w6XThfROiCGzwukxR1zhBIeu0RL0utLRiSAA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

4 participants