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

fix: local Error class extending global Error class. #110

Merged
merged 1 commit into from
Sep 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,11 @@ public Void caseStringType() {

@Override
public Void caseObjectType(ObjectType type) {
if (type.getDisplayName() != null && type.getDisplayName().equals("Error")) {
// global Error is aliased as GlobalError in closure.lib.d.ts.
emit("GlobalError");
return null;
}
// Closure doesn't require that all the type params be declared, but TS does
if (!type.getTemplateTypeMap().isEmpty()
&& !typeRegistry.getNativeType(OBJECT_TYPE).equals(type)) {
Expand Down
7 changes: 7 additions & 0 deletions src/resources/closure.lib.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Work around for https://github.com/Microsoft/TypeScript/issues/983
// All Cl2dts namespaces are below ಠ_ಠ.cl2dts_internal, thus
// this acts as global.
declare namespace ಠ_ಠ.cl2dts_internal {
type GlobalError = Error;
var GlobalError: ErrorConstructor;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void testDeclarationSyntax() throws Exception {

final List<String> tscCommand =
Lists.newArrayList(TSC.toString(), "--noEmit", "--skipDefaultLibCheck");
tscCommand.add("src/resources/closure.lib.d.ts");
tscCommand.addAll(goldenFilePaths);
runChecked(tscCommand);
}
Expand All @@ -57,6 +58,7 @@ public void testDeclarationUsage() throws Exception {
List<File> inputs = DeclarationGeneratorTests.getTestInputFiles(TS_SOURCES);
final List<String> tscCommand =
Lists.newArrayList(TSC.toString(), "--noEmit", "--skipDefaultLibCheck", "-m", "commonjs");
tscCommand.add("src/resources/closure.lib.d.ts");
for (File input : inputs) {
tscCommand.add(input.getPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ declare namespace ಠ_ಠ.cl2dts_internal.typesWithExterns {
function topLevelFunction ( ...a : any [] ) : any ;
interface ExtendsIThenable extends PromiseLike < any > {
}
class Error extends GlobalError {
}
}
declare module 'goog:typesWithExterns' {
import alias = ಠ_ಠ.cl2dts_internal.typesWithExterns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,10 @@ typesWithExterns.topLevelFunction = function() {};
* @interface
* @extends {IThenable}
*/
typesWithExterns.ExtendsIThenable = function() {};
typesWithExterns.ExtendsIThenable = function() {};

/**
* @constructor
* @extends {Error}
*/
typesWithExterns.Error = function() {};
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {elementMaybe, id} from 'goog:typesWithExterns';
import {elementMaybe, id, Error} from 'goog:typesWithExterns';

var el: Element = elementMaybe();
var els: ArrayLike<any> = id(document.getElementsByClassName('foo'));

var myError: Error = new Error();