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

How to extract interface from class, exact match #2908

Open
zerkalica opened this issue Nov 28, 2016 · 0 comments
Open

How to extract interface from class, exact match #2908

zerkalica opened this issue Nov 28, 2016 · 0 comments

Comments

@zerkalica
Copy link

zerkalica commented Nov 28, 2016

How to extract properties interface from class and do exact match?

class A {
 a: string
}

const likeA: $ShapeWithExactMatch<A> = {} // need a: string

I try $Shape, but it do not exact match.

EDIT: Full example

export default class A {
    some: string

    constructor<K: {[_: $Keys<A>]: string}>(rec?: K, old?: K) {
        Object.assign(this, this.constructor.defaults, rec, old)
    }

    copy(rec: {[_: $Keys<A>]: string}): this {
        return new this.constructor(rec, this)
    }

    static defaults = {
         some: 'default'
    }
}

const a = new A({some: 'test'})
const b = a.copy({info: 'qq'}) 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants