We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
TypeScript Version: 2.1.4 / nightly (2.2.0-dev.20170102)
Code
class Tween<T>{ static get<T>(target: T): Tween<T> { return new Tween(target); } constructor(private target: T) { } public to(props: Partial<T>) { } } class DisplayObject { public x: number; public y: number; } class Button extends DisplayObject { public z: number; onClick = () => { let tween = Tween.get(this); tween.to({ x: 100 }); tween.to({ z: 100 }); tween.to({ a: 100 }); } }
Expected behavior:
let tween = Tween.get(this); tween.to({ x: 100 }); // right tween.to({ z: 100 }); // right tween.to({ a: 100 }); // compile error
Actual behavior:
let tween = Tween.get(this); tween.to({ x: 100 }); // compile error tween.to({ z: 100 }); // compile error tween.to({ a: 100 }); // compile error
The text was updated successfully, but these errors were encountered:
I have observed a possibly related issue in nightly (2.2.0-dev.20170103) with the code:
export abstract class A<P> { public props: P; } export abstract class B<T, P extends { params: T }> extends A<P> { public get params(): this['props']['params'] { return this.props.params; } update(params: Partial<this['params']>) { // ... } } export interface P { x: number, y: string } export class C extends B<P, { params: P }> { f() { const p = this.params; this.update({ x: p.x + 1 }); // compile error here } }
Sorry, something went wrong.
Who can give me a feedback ?
@ahejlsberg @DanielRosenwasser
@WanderWang I'd suggest changing the to method to use Pick<T, K>:
to
Pick<T, K>
public to<K extends keyof T>(props: Pick<T, K>) { }
For more discussion on a similar issue, see #12793.
thanks @ahejlsberg , it works !!! I think I can close this issue and concern about #12793
No branches or pull requests
TypeScript Version: 2.1.4 / nightly (2.2.0-dev.20170102)
Code
Expected behavior:
Actual behavior:
The text was updated successfully, but these errors were encountered: