Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Extending lib.d.ts classes like Error is broken when name is aliased #81

Closed
rkirov opened this issue Sep 2, 2015 · 4 comments
Closed
Assignees

Comments

@rkirov
Copy link
Contributor

rkirov commented Sep 2, 2015

/**
 * Base class for custom error objects.
 * @param {*=} opt_msg The message associated with the error.
 * @constructor
 * @extends {Error}
 */
goog.debug.Error = function(opt_msg) {...}

outputs

declare namespace ಠ_ಠ.cl2dts_internal.goog.debug { 
  class Error extends Error { ... }
}

which makes TS sad.

@alexeagle alexeagle self-assigned this Sep 3, 2015
@alexeagle
Copy link
Contributor

Not sure what to do here yet.
See microsoft/TypeScript#983 which discusses how it's impossible to reference the global-namespaced Error once the namespace contains a class called Error.
Maybe we should take all the built-in (non-namespaced) names and move them to the closure-internal namespace, like

class Error extends ಠ_ಠ.cl2dts_internal.Error {}

but then we need to declare all of those, and in practice the externs/esX.js files should model the same stdlib as the lib.d.ts so maybe we really want this to refer to the Error class from lib.d.ts.

@mprobst
Copy link
Contributor

mprobst commented Sep 4, 2015

We could just have a map of names that are defined in the global scope, like Error or String etc, and then alias them with some renaming trick (look of approval? Table flip guy?).

@rkirov
Copy link
Contributor Author

rkirov commented Sep 23, 2015

Yep, easiest solution would be to add the following

declare namespace ಠ_ಠ.cl2dts_internal {
  type GlobalError = Error;
}

and then just emit GlobalError instead of Error when someone was referencing the global Error. Now the question is whether this should be appended to lib.d.ts or live in its own .d.ts that we have to always pass to TSC.

@alexeagle
Copy link
Contributor

+1 for modifying whatever "standard lib" typescript receives rather than
another explicit input.
There is a way to do this where we don't modify the existing lib.d.ts, but
instead add a lib.closure.d.ts and make that a standard lib. I've seen
hints about how to do that, so I think we could figure it out.

On Tue, Sep 22, 2015 at 5:21 PM Rado Kirov notifications@github.com wrote:

Yep, easiest solution would be to add the following

declare namespace ಠ_ಠ.cl2dts_internal {
type GlobalError = Error;
}

and then just emit GlobalError instead of Error when someone was
referencing the global Error. Now the question is whether this should be
appended to lib.d.ts or live in its own .d.ts that we have to always pass
to TSC.


Reply to this email directly or view it on GitHub
#81 (comment)
.

rkirov added a commit that referenced this issue Sep 23, 2015
Introduces an auxillary .d.ts `closure.lib.d.ts` that needs to be
passed into all consumers of cl2dts.

Closes #81
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants