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 'set' of undefined at Object.trackReferencedAmbientModule #25714

Closed
wgcrouch opened this issue Jul 17, 2018 · 5 comments
Assignees
Labels
Bug A bug in TypeScript Domain: Transforms Relates to the public transform API Fixed A PR has been merged for this issue

Comments

@wgcrouch
Copy link

wgcrouch commented Jul 17, 2018

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:

@ghost ghost added Bug A bug in TypeScript Domain: Transforms Relates to the public transform API labels Jul 17, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jul 17, 2018

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.

@mmorearty
Copy link
Contributor

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

@mmorearty
Copy link
Contributor

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[]> => {
...

@mmorearty
Copy link
Contributor

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!

@weswigham
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Transforms Relates to the public transform API Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants