Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Localized Module Augmentation of Selection by Transition. #4

Closed
tomwanzek opened this issue Jun 25, 2016 · 1 comment
Closed

Localized Module Augmentation of Selection by Transition. #4

tomwanzek opened this issue Jun 25, 2016 · 1 comment

Comments

@tomwanzek
Copy link
Owner

The Selection interface defined in d3-selection is augmented in relation to transitions in d3-transition.

In the definitions this is handled using the standard module augmentation pattern in the d3-transition definition file:

declare module "d3-selection" {
    export interface Selection<GElement extends BaseType, Datum, PElement extends BaseType, PDatum>{
        // augmentation here
    }
}

The issue is that the interface augmentation is not localized in the following sense.

A module with the following imports works as intended:

// Module 'A'
import * as d3Selection from 'd3-selection';
import * as d3Transition from 'd3-transition';

The d3-transition module import extends the Selection object from the d3-selection module as per D3 and the relevant Selection interface is augmented correspondingly.

However, the following module, may exhibit interface bleed.

// Module 'B'
import * as d3Selection from 'd3-selection';

In module 'B', the Selection interface should not show properties related to transitions. This is true and a non-issue, if the d3-transition definitions file is not part of the project.
However, if the d3-transition module is part of the project, even when it is not locally imported into the module 'B' file, the Selection interface has been augmented with transition properties.

This issue seems to be related to the type script issue: Proposal: Localized typings for definition files.

Need to file issue/investigate on Typescript.

@tomwanzek tomwanzek added this to the Core Modules (Enhanced) milestone Jun 25, 2016
@tomwanzek tomwanzek self-assigned this Jun 25, 2016
@tomwanzek tomwanzek added the bug label Jun 26, 2016
tomwanzek added a commit that referenced this issue Jun 30, 2016
…est.ts to `d3Selection` for clarity. Added test segment at the end of the file related to #4.
@tomwanzek
Copy link
Owner Author

tomwanzek commented Jun 30, 2016

Added test segment showing module augmentation bleed:

d3-selection-test.ts has only the following import:

import * as d3Selection from '../../src/d3-selection';

At the end of the file, the following test segment indicates lines that are unexpectedly compiling
successfully:

// ---------------------------------------------------------------------------------------
// TEST OF GITHUB ISSUE #4 (https://github.com/tomwanzek/d3-v4-definitelytyped/issues/4)
// ---------------------------------------------------------------------------------------

// fails as expected, as transition(...) method and Transition<...> interface are not defined on d3-selection
// let transition : d3Selection.Transition<any,any,any,any> = d3Selection.transition('test');

// UNEXPECTEDLY does NOT FAIL as module augmentation of Selection<...> interface in d3-transition bleeds into this test module,
// although d3-transition has not been imported

let ghostTransition = body.transition('test'); // SHOULD FAIL, method transition(...) SHOULD NOT BE AVAILABLE on body Selection<...> without d3-transition import

ghostTransition.duration(500);  // SHOULD FAIL, ghostTransition has properties of Transition<...>

body.interrupt('test'); // SHOULD FAIL, method interrupt(...) SHOULD NOT BE AVAILABLE on body Selection<...> without d3-transition import

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

No branches or pull requests

1 participant