Typescript: TypeError: Cannot read property 'set' of undefined at Object.trackReferencedAmbientModule

Created on 17 Jul 2018  Β·  5Comments  Β·  Source: microsoft/TypeScript

I am getting the exception below when running tsc on a project. Unfortunately I cant seem to create a minimal example to reproduce it, but looking through the source of tsc, there seems to be a case where refs is undefined here: https://github.com/Microsoft/TypeScript/blob/831be5d0788467f7fe5d708f0d404661b82e5462/src/compiler/transformers/declarations.ts#L78


TypeScript Version: 2.9.2 seems to still happen with typescript@next


Search Terms:
Object.trackReferencedAmbientModule
Cannot read property 'set' of undefined

Code
I can't seem to create a reproducable example, and cannot upload the code causing the error as its proprietary.

Expected behavior: should compile correctly

Actual behavior:

Exeception thrown:

TypeError: Cannot read property 'set' of undefined at Object.trackReferencedAmbientModule (***/node_modules/typescript/lib/tsc.js:57838:18) at getNameOfSymbolAsWritten (***/node_modules/typescript/lib/tsc.js:24622:53) at symbolToTypeNode (***/node_modules/typescript/lib/tsc.js:24412:32) at typeToTypeNodeHelper (***/node_modules/typescript/lib/tsc.js:23908:28) at symbolToParameterDeclaration (***/node_modules/typescript/lib/tsc.js:24316:41) at ***/node_modules/typescript/lib/tsc.js:24256:89 at Array.map (<anonymous>) at signatureToSignatureDeclarationHelper (***/node_modules/typescript/lib/tsc.js:24256:55) at createTypeNodeFromObjectType (***/node_modules/typescript/lib/tsc.js:24030:49) at createAnonymousTypeNode (***/node_modules/typescript/lib/tsc.js:23997:42)

Playground Link:

Related Issues:

Bug Transforms Fixed

Most helpful comment

Your compiler options and repro are much appreciated ❀️ #25982 is up with the (very tiny) fix!

All 5 comments

We will need some code sample to be able to act on this. under the debugger, a symbol should have a declarations property that you can call ts.getSourceFileOfNode(symbol.declarations[0]), and that should have a fileName property that would tell you which source file causes the issue and which declaration specifically. this can help you share a repro.

I was able to make a minimal repro case. The code is below; I'll also attach it as a zip file.

build.sh (run this to repro):

#!/bin/bash

tsc  \
    --noResolve \
    --declaration \
    --module amd \
    --outFile out/datastore.bundle.js \
    src/datastore_result.ts \
    src/conditional_directive_field.ts \
    lib/lib.d.ts

src/conditional_directive_field.ts:

import * as DatastoreResult from "src/datastore_result";

export const build = (): DatastoreResult.T<string> => {
    return null;
};

src/datastore_result.ts:

import { Result } from "lib/result";

export type T<T> = Result<Error, T>;

lib/lib.d.ts:

declare module "lib/result" {
    export type Result<E extends Error, T> = (E & Failure<E>) | (T & Success<T>);
    export interface Failure<E extends Error> { }
    export interface Success<T> { }
}

Zip file:
repro.zip

I also stumbled across this really bizarre line in a generated .d.ts file β€” I think this is related. (I'm wrapping it for legibility, but it was one line in the original file).

export const getScvResult: <M extends ObjectModel, P>(
  builder: ProjectionBuilder<M, P>, 
  fieldDef: AbstractServerComputedValueField<P>
) => Result.Result<
  unknown.Unknown, 
  import("../../../../../../../worker-4-TsCompile/asana2/luna/web/datastore/projection/server_computed_value").DatastoreServerComputedValue
>;

Funny πŸ˜ƒ I love the import(...) inline in the declaration.

The above declaration was generated for the following TypeScript code:

export const getScvResult = <M extends ObjectModel, P>(
    builder: ProjectionBuilder<M, P>,
    fieldDef: AbstractServerComputedValueField<P>
): DatastoreResult.T<ScvPrimitive | string | string[]> => {
...

Hi @mhegazy , I just wanted to make sure that my comments above don't slip through the cracks. (I know it was only yesterday that I commented, but I get the impression you folks are deep into the 3.0 release process right now.)

I posted a nice small repro case for this issue, and it's preventing us from upgrading to 2.9.x or 3.0.x (I don't know what changes I would need to make to my code to work around it). Thanks!

Your compiler options and repro are much appreciated ❀️ #25982 is up with the (very tiny) fix!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blakeembrey picture blakeembrey  Β·  171Comments

metaweta picture metaweta  Β·  140Comments

xealot picture xealot  Β·  150Comments

tenry92 picture tenry92  Β·  146Comments

OliverJAsh picture OliverJAsh  Β·  242Comments