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

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

Closed
realyze opened this issue Feb 26, 2017 · 2 comments
Closed

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

realyze opened this issue Feb 26, 2017 · 2 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@realyze
Copy link

realyze commented Feb 26, 2017

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)

@blakeembrey
Copy link
Contributor

blakeembrey commented Feb 26, 2017

They should be the same. However, they are different depending on if you have import or export at the top-level. With import and export, you're writing a module augmentation (because the file is in "module mode"). Without them, you're writing a module declaration (because the file is in "global mode").

Edit: Your problem would be resolved if you do import * as react from 'react' before trying to augment it.

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Feb 27, 2017
@realyze realyze closed this as completed Apr 6, 2017
@realyze
Copy link
Author

realyze commented Apr 6, 2017

@blakeembrey Thanks a lot!

@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