-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
@typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedBugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Description
TypeScript Version: 2.0.3
Code
npm install --save moment moment-timezone @types/moment @types/moment-timezone
import * as moment from "moment";
import "moment-timezone";
console.log(moment().format());
console.log(moment().tz("America/New_York").format());
Expected behavior:
The code compiles without incident.
Actual behavior:
test.ts(5,22): error TS2339: Property 'tz' does not exist on type 'Moment'.
Discussion:
The file node_modules/moment/moment.d.ts (the underlying type definitions used by moment) declares:
declare function moment(): moment.Moment;
// [snip]
declare namespace moment {
// [snip]
interface Moment {
// [snip]
format(): string;
// [snip]
}
// [snip]
}
export = moment
While node_modules/@types/moment-timezone/index.d.ts contains:
import * as moment from 'moment';
export as namespace MomentTimezone;
export = moment;
declare module "moment" {
interface Moment {
tz(): string;
tz(timezone: string): Moment;
zoneAbbr() :Moment;
zoneName() :Moment;
}
// [snip]
}
This seems consistent with what the handbook says about declaration merging.
Metadata
Metadata
Assignees
Labels
@typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedBugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue