You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError: Cannot read property 'instantiations' of undefined when use as const #30664
import*astsfrom"typescript";constsource=`([\t'dependencies',\t'devDependencies',\t'peerDependencies',\t'optionalDependencies',\t'resolutions',] as const)\t.forEach(k => {\t\tconsole.log(k);\t});`;letresult=ts.transpileModule(source,{compilerOptions: {module: ts.ModuleKind.CommonJS}});console.log(JSON.stringify(result));
Expected behavior:
Actual behavior:
C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:89093
throw e;
^
TypeError: Cannot read property 'instantiations' of undefined
at createTypeReference (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:39071:31)
at createTypeFromGenericGlobalType (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:39495:61)
at createArrayType (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:39513:20)
at getBaseTypes (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:36591:47)
at resolveObjectTypeMembers (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:37283:29)
at resolveTypeReferenceMembers (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:37314:13)
at resolveStructuredTypeMembers (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:37884:25)
at getPropertyOfType (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:38405:32)
at checkPropertyAccessExpressionOrQualifiedName (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:49210:24)
at checkPropertyAccessExpression (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\typescript.js:49193:20)
Anders Hejlsberg (@ahejlsberg) I investigated this: inside createArrayType function on checker.ts, the variable globalReadonlyArrayType is undefined as if its initialization cannot find the ReadonlyArray declaration.
I cannot link to the lines because the file is too big for GitHub.
initialization cannot find the ReadonlyArray declaration.
That's kind of expected since there is no lib.xxx.d.ts used by transpileModule. Defining ReadonlyArray<T> in the transpiled file should work around the crash.
This probably needs an additional condition to check if the global type is actually available. Though I don't know what a reasonable fallback would be.
Note that this might happen for globalArrayType and friends.
Activity
j-oliveras commentedon Mar 30, 2019
Anders Hejlsberg (@ahejlsberg) I investigated this: inside
createArrayTypefunction on checker.ts, the variableglobalReadonlyArrayTypeis undefined as if its initialization cannot find theReadonlyArraydeclaration.I cannot link to the lines because the file is too big for GitHub.
ajafff commentedon Mar 30, 2019
That's kind of expected since there is no
lib.xxx.d.tsused bytranspileModule. DefiningReadonlyArray<T>in the transpiled file should work around the crash.This probably needs an additional condition to check if the global type is actually available. Though I don't know what a reasonable fallback would be.
Note that this might happen for
globalArrayTypeand friends.iFwu commentedon Apr 1, 2019
I have this issue when using parcel to compile typescript files that use
as constsyntax.patrickmichalina commentedon Apr 3, 2019
Seeing the same failure when applying
readonlyto tuples likereadonly [any, any]PopGoesTheWza commentedon Apr 3, 2019
I experience the same issue with typescript 3.4.1 while running
ts.transpileModuleon the sample code for Improved support for read-only arrays and tuplesError test code can be reduced to this:
ddrozdov commentedon Apr 12, 2019
Would you please release the fix as 3.4.x?
RyanCavanaugh commentedon Apr 12, 2019
Andrew Branch (@andrewbranch) please port the fix PR to the release-3.4 branch. Thanks!
andrewbranch commentedon Apr 12, 2019
Done: #30892
Jack-Works commentedon Apr 17, 2019
Happened on
(x: readonly T[])andrewbranch commentedon May 17, 2019
Re-closing as this has been released