Skip to content

Add Console types #452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
66 changes: 26 additions & 40 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3723,40 +3723,6 @@ interface ConcatParams extends Algorithm {
publicInfo?: Uint8Array;
}

/** Provides access to the browser's debugging console (e.g. the Web Console in Firefox). The specifics of how it works varies from browser to browser, but there is a de facto set of features that are typically provided. */
interface Console {
memory: any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following properties are now gone:

  • memory
  • exception
  • [mark]timeline[End]

Do you know who this is likely to break? People with dependencies on old versions of IE? Somebody else?

Copy link
Contributor Author

@saschanaz saschanaz Jun 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that I have to keep .memory and .exception for now because they are in Edge and Firefox although not in spec. .markTimeline is only in Edge (and not in IE11) in non-functional state.

assert(condition?: boolean, message?: string, ...data: any[]): void;
clear(): void;
count(label?: string): void;
debug(message?: any, ...optionalParams: any[]): void;
dir(value?: any, ...optionalParams: any[]): void;
dirxml(value: any): void;
error(message?: any, ...optionalParams: any[]): void;
exception(message?: string, ...optionalParams: any[]): void;
group(groupTitle?: string, ...optionalParams: any[]): void;
groupCollapsed(groupTitle?: string, ...optionalParams: any[]): void;
groupEnd(): void;
info(message?: any, ...optionalParams: any[]): void;
log(message?: any, ...optionalParams: any[]): void;
markTimeline(label?: string): void;
profile(reportName?: string): void;
profileEnd(reportName?: string): void;
table(...tabularData: any[]): void;
time(label?: string): void;
timeEnd(label?: string): void;
timeStamp(label?: string): void;
timeline(label?: string): void;
timelineEnd(label?: string): void;
trace(message?: any, ...optionalParams: any[]): void;
warn(message?: any, ...optionalParams: any[]): void;
}

declare var Console: {
prototype: Console;
new(): Console;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When was this valid, if ever? (At least, I tested it on V8 and didn't get anything; I don't have Firefox installed.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Console public constructor has ever existed, at least since the spec was first published in 2014.

IE11 somehow has it, though.

};

interface ConstantSourceNode extends AudioScheduledSourceNode {
readonly offset: AudioParam;
addEventListener<K extends keyof AudioScheduledSourceNodeEventMap>(type: K, listener: (this: ConstantSourceNode, ev: AudioScheduledSourceNodeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
Expand Down Expand Up @@ -18590,7 +18556,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler
}

/** A window containing a DOM document; the document property points to the DOM document loaded in that window. */
interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, WindowConsole, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage {
interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage {
readonly applicationCache: ApplicationCache;
readonly clientInformation: Navigator;
readonly closed: boolean;
Expand Down Expand Up @@ -18721,10 +18687,6 @@ declare var Window: {
new(): Window;
};

interface WindowConsole {
readonly console: Console;
}

interface WindowEventHandlersEventMap {
"afterprint": Event;
"beforeprint": Event;
Expand Down Expand Up @@ -19125,6 +19087,31 @@ declare var webkitRTCPeerConnection: {

declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject;

declare namespace console {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll re-test @mhegazy's question. Here's how I'll do it in case you want to try it yourself.

$ git checkout console
$ npm test
$ cp baselines/* ~/ts/src/lib
$ cd ~/ts
$ gulp
$ cd ~/dtslint-runner
$ npm run build
$ node bin/index.js --localTs ~/ts/built/local

You need clones of Typescript, dtslint-runner and DefinitelyTyped to make this work.

var memory: any;
function assert(condition?: boolean, ...data: any[]): void;
function clear(): void;
function count(label?: string): void;
function countReset(label?: string): void;
function debug(...data: any[]): void;
function dir(item?: any, options?: any): void;
function dirxml(...data: any[]): void;
function error(...data: any[]): void;
function exception(message?: string, ...optionalParams: any[]): void;
function group(...data: any[]): void;
function groupCollapsed(...data: any[]): void;
function groupEnd(): void;
function info(...data: any[]): void;
function log(...data: any[]): void;
function table(tabularData?: any, properties?: string[]): void;
function time(label?: string): void;
function timeEnd(label?: string): void;
function timeLog(label?: string, ...data: any[]): void;
function timeStamp(label?: string): void;
function trace(...data: any[]): void;
function warn(...data: any[]): void;
}

declare namespace WebAssembly {
interface CompileError {
}
Expand Down Expand Up @@ -19706,7 +19693,6 @@ declare function toString(): string;
declare function dispatchEvent(event: Event): boolean;
declare var sessionStorage: Storage;
declare var localStorage: Storage;
declare var console: Console;
/**
* Fires when the user aborts the download.
* @param ev The event.
Expand Down
66 changes: 26 additions & 40 deletions baselines/webworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -924,40 +924,6 @@ interface ConcatParams extends Algorithm {
publicInfo?: Uint8Array;
}

/** Provides access to the browser's debugging console (e.g. the Web Console in Firefox). The specifics of how it works varies from browser to browser, but there is a de facto set of features that are typically provided. */
interface Console {
memory: any;
assert(condition?: boolean, message?: string, ...data: any[]): void;
clear(): void;
count(label?: string): void;
debug(message?: any, ...optionalParams: any[]): void;
dir(value?: any, ...optionalParams: any[]): void;
dirxml(value: any): void;
error(message?: any, ...optionalParams: any[]): void;
exception(message?: string, ...optionalParams: any[]): void;
group(groupTitle?: string, ...optionalParams: any[]): void;
groupCollapsed(groupTitle?: string, ...optionalParams: any[]): void;
groupEnd(): void;
info(message?: any, ...optionalParams: any[]): void;
log(message?: any, ...optionalParams: any[]): void;
markTimeline(label?: string): void;
profile(reportName?: string): void;
profileEnd(reportName?: string): void;
table(...tabularData: any[]): void;
time(label?: string): void;
timeEnd(label?: string): void;
timeStamp(label?: string): void;
timeline(label?: string): void;
timelineEnd(label?: string): void;
trace(message?: any, ...optionalParams: any[]): void;
warn(message?: any, ...optionalParams: any[]): void;
}

declare var Console: {
prototype: Console;
new(): Console;
};

/** This Streams API interface provides a built-in byte length queuing strategy that can be used when constructing streams. */
interface CountQueuingStrategy extends QueuingStrategy {
highWaterMark: number;
Expand Down Expand Up @@ -5361,10 +5327,6 @@ declare var WindowClient: {
new(): WindowClient;
};

interface WindowConsole {
readonly console: Console;
}

interface WindowOrWorkerGlobalScope {
readonly caches: CacheStorage;
readonly crypto: Crypto;
Expand Down Expand Up @@ -5409,7 +5371,7 @@ interface WorkerGlobalScopeEventMap {
}

/** This Web Workers API interface is an interface representing the scope of any worker. Workers have no browsing context; this scope contains the information usually conveyed by Window objects — in this case event handlers, the console or the associated WorkerNavigator object. Each WorkerGlobalScope has its own event loop. */
interface WorkerGlobalScope extends EventTarget, WindowConsole, WindowOrWorkerGlobalScope, WorkerUtils {
interface WorkerGlobalScope extends EventTarget, WindowOrWorkerGlobalScope, WorkerUtils {
readonly caches: CacheStorage;
readonly isSecureContext: boolean;
readonly location: WorkerLocation;
Expand Down Expand Up @@ -5646,6 +5608,31 @@ declare var XMLHttpRequestUpload: {

declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject;

declare namespace console {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is going to be a breaking change. i will need to run the tests against definitelytyped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would type Console = typeof console; mitigate the compat problem?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is that augmentation to Console are now ignored. making it a type makes it an error. but does not address the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My quick search on DefinitelyTyped (with a search query interface Console ) says only arangodb augments the existing Console definition, other types including Node.js and react-native have their own ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extends Console also only shows core-js.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The arangodb type is not really about augmenting existing browser console but about typing their own console module: https://github.com/arangodb/arangodb/blob/16a1fabf2057fb1da56a7abd44bd8e27ab1bead5/js/common/bootstrap/modules/console.js

core-js dropped their core.log that was using extends Console 4 years ago. (DefinitelyTyped/DefinitelyTyped#36100)

var memory: any;
function assert(condition?: boolean, ...data: any[]): void;
function clear(): void;
function count(label?: string): void;
function countReset(label?: string): void;
function debug(...data: any[]): void;
function dir(item?: any, options?: any): void;
function dirxml(...data: any[]): void;
function error(...data: any[]): void;
function exception(message?: string, ...optionalParams: any[]): void;
function group(...data: any[]): void;
function groupCollapsed(...data: any[]): void;
function groupEnd(): void;
function info(...data: any[]): void;
function log(...data: any[]): void;
function table(tabularData?: any, properties?: string[]): void;
function time(label?: string): void;
function timeEnd(label?: string): void;
function timeLog(label?: string, ...data: any[]): void;
function timeStamp(label?: string): void;
function trace(...data: any[]): void;
function warn(...data: any[]): void;
}

declare namespace WebAssembly {
interface Global {
value: any;
Expand Down Expand Up @@ -5828,7 +5815,6 @@ declare var navigator: WorkerNavigator;
declare function importScripts(...urls: string[]): void;
declare function atob(encodedString: string): string;
declare function btoa(rawString: string): string;
declare var console: Console;
declare var caches: CacheStorage;
declare var crypto: Crypto;
declare var indexedDB: IDBFactory;
Expand Down
29 changes: 29 additions & 0 deletions inputfiles/idl/Console.widl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[Exposed=(Window,Worker,Worklet)]
namespace console { // but see namespace object requirements below
// Logging
void assert(optional boolean condition = false, any... data);
void clear();
void debug(any... data);
void error(any... data);
void info(any... data);
void log(any... data);
void table(optional any tabularData, optional sequence<DOMString> properties);
void trace(any... data);
void warn(any... data);
void dir(optional any item, optional object? options);
void dirxml(any... data);

// Counting
void count(optional DOMString label = "default");
void countReset(optional DOMString label = "default");

// Grouping
void group(any... data);
void groupCollapsed(any... data);
void groupEnd();

// Timing
void time(optional DOMString label = "default");
void timeLog(optional DOMString label = "default", any... data);
void timeEnd(optional DOMString label = "default");
};
4 changes: 4 additions & 0 deletions inputfiles/idlSources.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"title": "Compatibility",
"deprecated": true
},
{
"url": "https://console.spec.whatwg.org/",
"title": "Console"
},
{
"url": "https://www.w3.org/TR/credential-management-1/",
"title": "Credential Management"
Expand Down
100 changes: 27 additions & 73 deletions inputfiles/overridingTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -994,79 +994,6 @@
}
}
},
"Console": {
"name": "Console",
"methods": {
"method": {
"debug": {
"name": "debug",
"override-signatures": [
"debug(message?: any, ...optionalParams: any[]): void"
]
},
"dir": {
"name": "dir",
"override-signatures": [
"dir(value?: any, ...optionalParams: any[]): void"
]
},
"dirxml": {
"name": "dirxml",
"override-signatures": [
"dirxml(value: any): void"
]
},
"error": {
"name": "error",
"override-signatures": [
"error(message?: any, ...optionalParams: any[]): void"
]
},
"info": {
"name": "info",
"override-signatures": [
"info(message?: any, ...optionalParams: any[]): void"
]
},
"log": {
"name": "log",
"override-signatures": [
"log(message?: any, ...optionalParams: any[]): void"
]
},
"warn": {
"name": "warn",
"override-signatures": [
"warn(message?: any, ...optionalParams: any[]): void"
]
},
"group": {
"name": "group",
"override-signatures": [
"group(groupTitle?: string, ...optionalParams: any[]): void"
]
},
"groupCollapsed": {
"name": "groupCollapsed",
"override-signatures": [
"groupCollapsed(groupTitle?: string, ...optionalParams: any[]): void"
]
},
"trace": {
"name": "trace",
"override-signatures": [
"trace(message?: any, ...optionalParams: any[]): void"
]
},
"profileEnd": {
"name": "profileEnd",
"override-signatures": [
"profileEnd(reportName?: string): void"
]
}
}
}
},
"FormData": {
"name": "FormData",
"methods": {
Expand Down Expand Up @@ -3237,6 +3164,33 @@
]
},
"namespaces": [
{
"name": "console",
"methods": {
"method": {
"exception": {
"name": "exception",
"override-signatures": [
"exception(message?: string, ...optionalParams: any[]): void"
]
},
"timeStamp": {
"name": "timeStamp",
"override-signatures": [
"timeStamp(label?: string): void"
]
}
}
},
"properties": {
"property": {
"memory": {
"name": "memory",
"type": "any"
}
}
}
},
{
"name": "WebAssembly",
"methods": {
Expand Down
15 changes: 5 additions & 10 deletions inputfiles/removedTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,7 @@
}
},
"ClipboardItem": null,
"Console": {
"methods": {
"method": {
"msIsIndependentlyComposed": null,
"select": null
}
}
},
"Console": null,
"CSSStyleDeclaration": {
"properties": {
"property": {
Expand Down Expand Up @@ -321,12 +314,14 @@
"GlobalFetch",
"IDBEnvironment",
"WindowBase64",
"WindowTimers"
"WindowTimers",
"WindowConsole"
]
},
"WorkerGlobalScope": {
"implements": [
"GlobalFetch"
"GlobalFetch",
"WindowConsole"
]
},
"XPathNSResolver": null
Expand Down