Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Merged declarations are not written to the parent #32298

Copy link
Copy link
@fidian

Description

@fidian
Issue body actions

TypeScript Version: 3.6.0-dev.20190704

Search Terms: merge declarations augment grafting

Code

parent.ts:

import { child1 } from './child1';

export class ParentThing implements ParentThing {}

// Add extra methods to this object.
child1(ParentThing.prototype);
// Imagine many more get added as well.

child1.ts:

import { ParentThing } from './parent';

declare module './parent' {
    interface ParentThing {
        add: (a: number, b: number) => number;
    }
}

export function child1(prototype: ParentThing) {
    prototype.add = (a: number, b: number) => a + b;
}

test.ts:

// Use this to test before compilation
import { ParentThing } from './parent';

// Use this to test after compilation
// import { ParentThing } from '../lib/parent';

const parentThing = new ParentThing();

console.log(parentThing.add(1, 1));

Expected behavior:

When tsc compiles the project, I should not lose the definitions. I want to be able to use the generated code as a module and still see the augmented type and be able to follow through to the methods that are defined by all children.

Several children are adding many methods to the parent.

Actual behavior:

Before compilation, there is no problem. I can jump to the definition when test.js is pointing to parent.ts. The declarations are merged and I can immediately access the add method in child1.

After compilation and when I change the test to load the compiled version, I get an error message: "Property 'add' does not exist on type 'ParentThing'."

Playground Link: None.

Related Issues: None that I could find.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.