benmerckx / genes

Generates split ES6 modules and Typescript definitions from Haxe modules.
43 stars 8 forks source link

Name clash with global types #48

Open kevinresol opened 3 years ago

kevinresol commented 3 years ago
Promise != cast js.lib.Promise; // should be false, but got true

// name clash with js.lib.Promise
class Promise {}

ref:

benmerckx commented 3 years ago

$global.GlobalType should not be used in type definitions. Not sure how to fix the issue there

kevinresol commented 3 years ago

Perhaps we should just prefix the type with $ when it is using a globally reserved name

kevinresol commented 3 years ago

or we can use a prefixed name internally, this seems to work:

// main.ts
import {Promise as Promise__1} from './mypromise'

var customPromise = new Promise__1();
var globalPromise = new Promise<number>(null);

Promise__1.foo(globalPromise);

// mypromise.ts
class $Promise {
    static foo(input:Promise<number>) {}
}

export const Promise = $Promise