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

TypeError: Cannot read property 'length' of undefined #22948

Closed
bildja opened this issue Mar 28, 2018 · 2 comments · Fixed by #22970
Closed

TypeError: Cannot read property 'length' of undefined #22948

bildja opened this issue Mar 28, 2018 · 2 comments · Fixed by #22970
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@bildja
Copy link

bildja commented Mar 28, 2018

TypeScript Version: 2.9.0-dev.20180328

Code

import * as React from 'react';

const Test123 = () => <div/>;

function testComponent(props) {
    return <Test123 {...props}/>;
}

Expected behavior:
No errors

Actual behavior:
Exceptions:

TypeError: Cannot read property 'length' of undefined
    at Object.unescapeLeadingUnderscores (/node_modules/typescript/lib/typescript.js:12280:19)
    at checkJsxAttributesAssignableToTagNameAttributes (/typescript/lib/typescript.js:40117:146)
    at checkJsxOpeningLikeElementOrOpeningFragment (/node_modules/typescript/lib/typescript.js:40052:17)
    at checkJsxSelfClosingElement (/node_modules/typescript/lib/typescript.js:39449:13)
    at checkExpressionWorker (/node_modules/typescript/lib/typescript.js:43637:28)
    at checkExpression (/node_modules/typescript/lib/typescript.js:43530:42)
    at checkExpressionCached (/node_modules/typescript/lib/typescript.js:43396:38)
    at getReturnTypeFromBody (/node_modules/typescript/lib/typescript.js:42348:24)
    at getReturnTypeOfSignature (/node_modules/typescript/lib/typescript.js:31762:28)
    at checkFunctionExpressionOrObjectLiteralMethodDeferred (/node_modules/typescript/lib/typescript.js:42632:21)
@jaydh
Copy link

jaydh commented Mar 28, 2018

You're not giving props a type definition so it could be undefined and here the typeerror is coming from the spread operator because typescript can't be sure what you're passing in can be spread

@bildja
Copy link
Author

bildja commented Mar 28, 2018

@jaydh that's right, it anyway should not raise an exception on compile time. And it used to work prior to 2.8.0

@ghost ghost added the Bug A bug in TypeScript label Mar 28, 2018
@mhegazy mhegazy added this to the TypeScript 2.9 milestone Mar 28, 2018
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Mar 29, 2018
@mhegazy mhegazy modified the milestones: TypeScript 2.9, TypeScript 2.8.2 Mar 29, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 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

Successfully merging a pull request may close this issue.

4 participants