Created
July 4, 2019 07:58
-
-
Save aiya000/8ac0241de8400d8c90d2a292055c5baf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import deprecated from 'deprecated-decorator' | |
class Untyped { | |
public set(_: string, __: any): void { } | |
} | |
class Typed<T extends object> extends Untyped { | |
public assign(x: AFieldOf<T>, __: Typed[x]) { } // 依存型させてぇ! | |
@deprecated('assign') | |
public set(_: string, __: any): void { } | |
} | |
type TupleToUnion<T> = T extends (infer I)[] ? I : never | |
type AFieldOf<T> = TupleToUnion<[keyof T]> | |
const x = new Typed<{ x: number }>() | |
x.assign('x', 10) | |
x.set('x', 20) | |
console.log(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment