1

I have a type named the same as a global type. Specifically, an Event.

I've put my Event inside a namespace, which makes referring to it outside the namespace easy, but inside the namespace I can't refer to the global (or standard) one.

namespace Dot {
    export class Event {
        // a thing happens between two parties; nothing to do with JS Event
    }
    function doStuff(e : Event) {
       // Event is presumed to be a Dot.Event instead of usual JS event
       // Unable to refer to global type?
    }
}
function doStuff2(e : Event) {
    // Use of regular Event type, cool
}
function doStuff3(e : Dot.Event) {
    // Use of Dot event type, cool
}

I suspect this is simply not possible, but can this be confirmed? Any workarounds besides renaming the Dot.Event type?

Cheers

1

1 Answer 1

4

You could create a type to represent the global Event type, and use it within the namespace:

type GlobalEvent = Event;

namespace Dot {
    export class Event {
        // a thing happens between two parties; nothing to do with JS Event
    }
    function doStuff(e : GlobalEvent) {
       // Event is presumed to be a Dot.Event instead of usual JS event
       // Unable to refer to global type?
    }
}
function doStuff2(e : Event) {
    // Use of regular Event type, cool
}
function doStuff3(e : Dot.Event) {
    // Use of Dot event type, cool
}

But my recommendation would be to call your specialisation something else, for example DotEvent.

Sign up to request clarification or add additional context in comments.

1 Comment

That's what I was looking for. The majority of Dot's code uses DotEvent, it's just the event listeners inside Dot that need standard Event, so I'll be going with your GlobalEvent method. Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.