Skip to content

Instantly share code, notes, and snippets.

@aiya000
Created July 4, 2019 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aiya000/8ac0241de8400d8c90d2a292055c5baf to your computer and use it in GitHub Desktop.
Save aiya000/8ac0241de8400d8c90d2a292055c5baf to your computer and use it in GitHub Desktop.
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