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

Weird uninitialized variable error for destructured members of type parameter constrained to homomorphic mapped type where member is declared optional #20994

Closed
DanielRosenwasser opened this issue Jan 3, 2018 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@DanielRosenwasser
Copy link
Member

Found in Formik by @weswigham who patiently worked with me to find the minimal repro.

Run the following with strictNullChecks

interface Options {
    a?: number | object;
    b: () => void;
}

class C<T extends Options> {
    foo!: { [P in keyof T]: T[P] }

    method() {
        let { a, b } = this.foo;
        !(a && b)
        a
        // TypeScript issues an error on 'a' above:
        // Variable 'a' is used before being assigned.'
    }
}
@rozzzly
Copy link

rozzzly commented Jan 4, 2018

@DanielRosenwasser

    foo!: { [P in keyof T]: T[P] }

Is the !: some new/obscure syntax I'm not aware of? Or just a typo?

@ahejlsberg
Copy link
Member

@rozzzly See #20166.

@sandersn
Copy link
Member

Should be fixed #20995

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jan 19, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

6 participants