Skip to content
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

Why the split declarations in lib.d.ts? #9154

Closed
mindplay-dk opened this issue Jun 14, 2016 · 2 comments
Closed

Why the split declarations in lib.d.ts? #9154

mindplay-dk opened this issue Jun 14, 2016 · 2 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@mindplay-dk
Copy link

Why are the declarations in lib.d.ts split into two?

interface Selection {
    anchorNode: Node;
    anchorOffset: number;
    focusNode: Node;
    focusOffset: number;
    isCollapsed: boolean;
    rangeCount: number;
    type: string;
    addRange(range: Range): void;
    collapse(parentNode: Node, offset: number): void;
    collapseToEnd(): void;
    collapseToStart(): void;
    containsNode(node: Node, partlyContained: boolean): boolean;
    deleteFromDocument(): void;
    empty(): void;
    extend(newNode: Node, offset: number): void;
    getRangeAt(index: number): Range;
    removeAllRanges(): void;
    removeRange(range: Range): void;
    selectAllChildren(parentNode: Node): void;
    setBaseAndExtent(baseNode: Node, baseOffset: number, extentNode: Node, extentOffset: number): void;
    toString(): string;
}

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

Why isn't this declared as a class?

declare class Selection {
    constructor();

    anchorNode: Node;
    anchorOffset: number;
    focusNode: Node;
    focusOffset: number;
    isCollapsed: boolean;
    rangeCount: number;
    type: string;
    addRange(range: Range): void;
    collapse(parentNode: Node, offset: number): void;
    collapseToEnd(): void;
    collapseToStart(): void;
    containsNode(node: Node, partlyContained: boolean): boolean;
    deleteFromDocument(): void;
    empty(): void;
    extend(newNode: Node, offset: number): void;
    getRangeAt(index: number): Range;
    removeAllRanges(): void;
    removeRange(range: Range): void;
    selectAllChildren(parentNode: Node): void;
    setBaseAndExtent(baseNode: Node, baseOffset: number, extentNode: Node, extentOffset: number): void;
    toString(): string;
}

These split declarations are seen as two declarations by VS Code, which doesn't work very well, e.g. doesn't show you the interface members in the pop-up:

image

Can't you merge these?

@plantain-00
Copy link
Contributor

@mhegazy
Copy link
Contributor

mhegazy commented Jun 14, 2016

Why are the declarations in lib.d.ts split into two?

The reason is rather historic. back in 0.8.* time classes and interfaces did not merge, and we wanted these classes to be extensible.

The other part that makes blocks this conversion across the board is call signatures. there is no way now to define a call signature on a class. this is tracked by #183.

As @plantain-00 noted; the result of the split should not be of any much consequence. moving to classes, would allow extending the static side, which is not allowed now. not sure that this is a common scenario however.

Can't you merge these?

They can. I do agree it makes the declaration file cleaner and easier to read. this request is tracked by #574

@mhegazy mhegazy closed this as completed Jun 14, 2016
@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Jun 14, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants