typescript + type definition file (.d.ts) + enum (enum)

1

I'm trying to create a definition file that uses an enumerator, defined in another file, and a declared variable (declare var) in the .d.ts file, but when referencing this file in another implementation, it says that variable does not exist.

Removing import and declaring the enumerator in the .d.ts file the vmMessage variable normally recognizes, however the error occurs that the enumerator is not the same as the file type.enum.

If the way I did does not work, how can I declare an enumerator so that I can reuse it in multiple project locations?

type.enum.ts

export enum TipoMensagem {
    INFO = 0, ALERT = 1, ERROR = 2, OK = 3
}

export enum FiltroLogica {
    E = 1, OU = 2
}      

vm.message.d.ts

/// <reference path="../../knockout/knockout.d.ts" />

import Enums = require("app/types/type.enum");

interface Mensagem {
    tipo: Enums.TipoMensagem;
    texto: string;
}

interface MensagemVM {
    listaMensagem: KnockoutObservableArray<Mensagem>;
    ExibirMensagem(tipo: Enums.TipoMensagem, texto: string): void;
    FadeIn(elem, index, item): void;
}

declare var vmMensagem: MensagemVM;

type.message.ts

/// <reference path="../../typings/vms/common/vm.mensagem.d.ts" />

import Enums = require("app/types/type.enum");

class Mensagem {

    tipo: Enums.TipoMensagem;
    texto: string;

    public constructor(tipo: Enums.TipoMensagem, txt: string) {
        this.tipo = tipo;
        this.texto = txt;
    }

    //Exibe a mensagem no elemento informado
    public SetElement(htmlElem: HTMLElement): void {
        $(htmlElem).delay(5000).fadeOut(600, () => {
            if (vmMensagem.listaMensagem.length == 0)
                return;

            $(this).remove();
            vmMensagem.listaMensagem.remove(this);
        });
    }
} 

export = Mensagem;

In type.message.ts in the public function SetElement (htmlElem: HTMLElement): void compilation error Could not find symbol 'VmMessage'.

    
asked by anonymous 05.12.2014 / 12:15

1 answer

1

I was able to solve my problem.

I removed the type.enum.ts file and created a new one (enum.d.ts ) containing the enumerators, referencing it in the required files, you must import the file containing the enumerators in which the generated .js already has the values applied directly, serving only as a reference in development.

enum.d.ts

declare module Enums {
    enum TipoMensagem {
        INFO = 0, ALERT = 1, ERROR = 2, OK = 3
    }

    enum FiltroLogica {
        E = 1, OU = 2
    }
} 
    
05.12.2014 / 13:49