Repository navigation
Visitor throws Cannot read property 'kind' of undefined using TypeScript@3.9.2Β #38558
Description
Activity
I managed to reduce the reproduction code down to:
const f = (props: any) => (...args: any) => ''; f({ background: `${1} anything`, ...{ test: 1 }, })``
The issue is in the es2015 transformer so any target above es2015 will be fine. In fact, the issue is in the object literal visitor when the node contains "es2015 features (eg. template literals, arrow functions, ...)" that need to be transformed. So you can reproduce the same crash with this code using arrow functions:
const f = (props: any) => (...args: any) => ''; f({ background: (() => 1)(), ...{ test: 1 }, })``
This code, for instance does not crash because the object literal doesn't have any es2015 features in it.
const f = (props: any) => (...args: any) => ''; f({ background: 'anything', ...{ test: 1 }, })``
I'll try to fix this.
Until the bug is fixed, Lukas Klusis (@lukaskl) you can use a string instead of a template literal for the background variable or use an external variable to store the template literal outside of the object literal like that:
export interface ColorProps { style?: CSSProperties } const Color = styled(({ style }: ColorProps) => { const background = `${1 + 1}`; return ( <div style={{ ...style, background, }} /> ); })``
Reacted by Lukas KlusisThank you Lissein (@lissein) for investigating this!
To add another workaround, it is also possible to split this into two definitions, e.g.:
const ColorUnstyled = ({ style }: ColorProps) => ( <div style={{ ...style, background: `anything`, }} /> ) const Color = styled(ColorUnstyled)``
Reacted by LisseinAfter more investigations, I confirmed that the code crashing is in the es2015 transformer but the root cause is not in here. The bug is actually in the es2018 transformer.
Here is an example of code with a target es2017 (< es2018):const f = (props: any) => (...args: any) => ''; f({ background: (() => 1)(), ...{ test: 1 }, })`` const a = { ...{ test: 1 }, }
"use strict"; const f = (props) => (...args) => ''; f({ background: (() => 1)(), ...{ test: 1 }, }) ``; const a = Object.assign({ test: 1 });
As you can see, the second spread is transpiled correctly but the first one isn't.
- added this to the TypeScript 3.9 May 2020 Servicing Release milestone
on May 14, 2020 elibarzilay commented
on May 15, 2020 ContributorMore actions(This is most likely very unrelated to #38383...)
- added 2 commits that reference this issue
on May 15, 2020 - added a commit that references this issue
on May 15, 2020 tscthrows the same error for me with TypeScript version 3.9.7:Chase@DESKTOP-P21MP39 MINGW64 ~/company/companyWeb/projects/company.Server.Web ((b99b96a0de...)) $ node_modules/typescript/bin/tsc C:\Users\Chase\company\companyWeb\projects\company.Server.Web\node_modules\typescript\lib\tsc.js:82931 throw e; ^ TypeError: Cannot read property 'kind' of undefined at visitObjectLiteralExpression (C:\Users\Chase\company\companyWeb\projects\company.Server.Web\node_modules\typescript\lib\tsc.js:70631:35) at visitJavaScript (C:\Users\Chase\company\companyWeb\projects\company.Server.Web\node_modules\typescript\lib\tsc.js:69611:28) at visitor (C:\Users\Chase\company\companyWeb\projects\company.Server.Web\node_modules\typescript\lib\tsc.js:69554:24) at visitNode (C:\Users\Chase\company\companyWeb\projects\company.Server.Web\node_modules\typescript\lib\tsc.js:63010:23) at Object.visitEachChild (C:\Users\Chase\company\companyWeb\projects\company.Server.Web\node_modules\typescript\lib\tsc.js:63260:45) at visitParenthesizedExpression (C:\Users\Chase\company\companyWeb\projects\company.Server.Web\node_modules\typescript\lib\tsc.js:70365:23) at visitJavaScript (C:\Users\Chase\company\companyWeb\projects\company.Server.Web\node_modules\typescript\lib\tsc.js:69625:28) at visitor (C:\Users\Chase\company\companyWeb\projects\company.Server.Web\node_modules\typescript\lib\tsc.js:69554:24) at Object.visitNode (C:\Users\Chase\company\companyWeb\projects\company.Server.Web\node_modules\typescript\lib\tsc.js:63010:23) at transformFunctionBody (C:\Users\Chase\company\companyWeb\projects\company.Server.Web\node_modules\typescript\lib\tsc.js:70307:37)My project is quite large. I don't know which code
tscfails on.Edit: This happens when I try to upgrade directly from typescript version 3.7.3 to 3.9.7. Version 3.7.3 works for me.
Why has this issue been closed, what is the resolution without having to make manual code changes? I'm facing the same issue on 3.9.10, targetting ES5
- locked as resolved and limited conversation to collaborators
on Oct 21, 2025
TypeScript Version:
3.9.23.9.1-rc3.9.0-beta3.8.3(it work with previous versions)Search Terms:
Visitor TypeError kind undefined 85032
Code
Unknown (Error is thrown at
node_modules/typescript/lib/typescript.js:85032:35)But this part triggers it
Expected behavior:
It compiles
Actual behavior:
Playground Link:
Related Issues: