0

Initially I declared everything in ambient module. Later I had to extract enums to non-ambient module, because I needed enum member lookup, with declare and const its not possible. Now my sample files look as following

//enums.ts
export enum Enum1{
    Value1, Value2
}

//ambient.d.ts
import * as enums from "./enums";
declare interface TypeA
{
  enumField: enums.Enum1;
  strField: string;
}

//consumer.ts
/// <reference path="ambient.d.ts"/>
class Consumer{
 memberField: TypeA; // <= Here compiler cannot find TypeA
}

What am I doing wrong and how should I proceed?

Otabek Kholikov
  • 1,188
  • 11
  • 19

2 Answers2

1

As soon as you add line:

import * as enums from "./enums";

you convert it to external module, and therefore to access its content need to import it, like this:

import * as amb from './ambient'
class Consumer
{
    memberField: amb.TypeA; 
}

As a side note. Do not use namespaces or try to mix them with modules (link, link).

Community
  • 1
  • 1
Amid
  • 21,508
  • 5
  • 57
  • 54
1

You can add the following import {TypeA} from "./ambient";

import {TypeA} from "./classes/ambient"; //change your path

//consumer.ts
/// <reference path="./classes/ambient.d.ts"/>

class Consumer{
 memberField: TypeA;
}

//ambient.d.ts
import * as enums from "./enums";

export declare interface TypeA
{
  enumField: enums.Enum1;
  strField: string;
}
Angel Angel
  • 19,670
  • 29
  • 79
  • 105