Skip to content

Extending a namespace in .d.ts file vs in .ts file #14325

@realyze

Description

@realyze

Typescript@2.1.6

Using "@types/react": "^0.14.41", and "@types/react-dom": "^0.14.18" (installed via npm).

When I write

declare module 'react' {
    interface HTMLProps<T> {
        onTouchTap?: React.EventHandler<React.TouchEvent<T>>;
    }
}

in a customTypings/react-tap-touch.d.ts file, it seems to cause tsc to report a lot of errors (error TS2604: JSX element type 'Router' does not have any construct or call signatures and similar). Looks like react namespace is overriden rather than extended.

Using the same snippet in a startup.ts file works fine (i.e., extends react and doesn't override it).

What's the difference between extending a namespace from .d.ts vs .ts file? Shouldn't .d.ts be the right place to do this sort of thing?

The issue is summed up by this comment:
zilverline/react-tap-event-plugin#58 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions