Skip to content

v2.3.2: spreading objects of type any seems to be removing imports #15546

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

Closed
dzearing opened this issue May 3, 2017 · 2 comments
Closed

v2.3.2: spreading objects of type any seems to be removing imports #15546

dzearing opened this issue May 3, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@dzearing
Copy link
Member

dzearing commented May 3, 2017

TypeScript Version: 2.3.2 (also repros in 2.3.1, but not 2.2.1)

Code

We're seeing problems with spreading objects that aren't typed correctly.

This works, notice that styles has a type of empty object:

import * as React from 'react';
import { animationClassNames } from '@uifabric/styling';

let styles: {} = {};

export function testMe() {
  return <div { ...styles }>{ animationClassNames } />;
}

The output generated successfully requires the styling package stored in the styling_1 variable:

var React = require("react");
var styling_1 = require("@uifabric/styling");
var styles = {};
function testMe() {
    return React.createElement("div", tslib_1.__assign({}, styles),
        styling_1.animationClassNames,
        " />; }");
}

However, if the styles object is of type any, the styling_1 variable disappears, and causes nastiness downstream.

Typescript:

import * as React from 'react';
import { animationClassNames } from '@uifabric/styling';

let styles: any = {};

export function testMe() {
  return <div { ...styles }>{ animationClassNames } />;
}

Generated JavaScript, where did styling_1 go?

var tslib_1 = require("tslib");
var React = require("react");
var styles = {};
function testMe() {
    return React.createElement("div", tslib_1.__assign({}, styles),
        styling_1.animationClassNames,
        " />; }");
}
exports.testMe = testMe;

Expected behavior:

Spreading objects without typings doesn't break things.

Actual behavior:

Unexpected breakage.

Note that I'm using any here as an example; we've seen this happening in places where the object is of type React.HTMLProps<HTMLDivElement> and we don't understand. We've seen a number of errors from 2.3.2 where the compiler is complaining about spreading objects in JSX that are definitely objects of some interface shape but TypeScript isn't recognizing them.

@dzearing
Copy link
Member Author

dzearing commented May 3, 2017

Looks like a dupe of #15478, but in this case imports are being stripped. Feel free to close and track there, if this is the same. It's important to fix asap.

@mhegazy
Copy link
Contributor

mhegazy commented May 3, 2017

This is caused by the same underlying issue as #15469. it should be fixed by #15548. The fix should be available in typescript@next tomorrow (5/4), please give it a try and let us know if you are still seeing issues.

@mhegazy mhegazy closed this as completed May 3, 2017
@mhegazy mhegazy added the Duplicate An existing issue was already created label May 3, 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

2 participants