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

Spread attribute syntax makes compilation and type checking ignore errors and module imports #15625

Closed
phurytw opened this issue May 6, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@phurytw
Copy link

phurytw commented May 6, 2017

TypeScript Version: 2.3.2 (VSCode / Windows)

Code

import * as React from "react";
import { style } from "./classNames";

export class Component extends React.Component<React.HTMLProps<HTMLDivElement>, {}> {
    constructor(props?: React.HTMLProps<HTMLDivElement>) {
        super(props);
    }
    render(): JSX.Element {
        const props: any = this.props;
        return <div
            {...props}
            className={style}
        >
            <p>Content</p>
        </div>;
    }
}

Expected behavior:
Compiled code should have require("./classNames");.
Actual behavior:
require("./classNames"); is not present.

I'm in a weird situation where TypeScript stops caring about whatever that is after a spread attributes syntax.

In the sample code I can't put {...this.props} because I would get this error: 'children' are specified twice. The attribute named 'children' will be overwritten. So I worked around it with the any variable.

But now the crazy thing is that everything after the spread syntax is "ignored" by TypeScript.

The compiler doesn't notify any further syntax errors and doesn't include the imported module that I use after the spread syntax. But it will successfully compile.

This is the compiled file of the above code. I believe I should get a require("./classNames") somewhere which I do get if I don't use the spread syntax.

Other examples

Using an undeclared variable before the spread syntax

Before spread
VSCode shows the error and I also get the following error when compiling: index.tsx(12,24): error TS2304: Cannot find name 'notDeclared'.

Using an undeclared variable after the spread syntax

After spread
VSCode ignores the error and I get no errors when compiling.

@mhegazy
Copy link
Contributor

mhegazy commented May 6, 2017

Duplicate of #15469. should be fixed in typescript@next, and will be part of the upcoming [email protected].

@mhegazy mhegazy added the Duplicate An existing issue was already created label May 6, 2017
@yuit
Copy link
Contributor

yuit commented May 8, 2017

Close for now @lith-light-g let us know if you still run into issue after update to typescript@next

@yuit yuit closed this as completed May 8, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants