Closed aslanovsergey closed 2 years ago
Did you install @types/moment-timezone
?
moment
doesn't contain moment-timezone
out of box like types of moment
don't contain @types/moment-timezone
.
Installed both, still Property 'tz' does not exist on type 'typeof moment'. Should I set it another way?
Can you publish your code here? In my current project I have
And I can access to tz
property like:
import * as moment from "moment-timezone";
moment.tz.setDefault("UTC");
moment-timezone.d.ts
just overrides moment
module and appends several properties:
import moment = require('moment');
// require("moment-timezone") === require("moment")
export = moment;
declare module 'moment' {
interface MomentZone {
name: string;
abbrs: string[];
untils: number[];
offsets: number[];
population: number;
abbr(timestamp: number): string;
offset(timestamp: number): number;
utcOffset(timestamp: number): number;
parse(timestamp: number): number;
}
interface MomentTimezone {
(): moment.Moment;
(timezone: string): moment.Moment;
(date: number, timezone: string): moment.Moment;
(date: number[], timezone: string): moment.Moment;
(date: string, timezone: string): moment.Moment;
(date: string, format: moment.MomentFormatSpecification, timezone: string): moment.Moment;
(date: string, format: moment.MomentFormatSpecification, strict: boolean, timezone: string): moment.Moment;
(date: string, format: moment.MomentFormatSpecification, language: string, timezone: string): moment.Moment;
(date: string, format: moment.MomentFormatSpecification, language: string, strict: boolean, timezone: string): moment.Moment;
(date: Date, timezone: string): moment.Moment;
(date: moment.Moment, timezone: string): moment.Moment;
(date: any, timezone: string): moment.Moment;
zone(timezone: string): MomentZone | null;
add(packedZoneString: string): void;
add(packedZoneString: string[]): void;
link(packedLinkString: string): void;
link(packedLinkString: string[]): void;
load(data: { version: string; links: string[]; zones: string[] }): void;
names(): string[];
guess(ignoreCache?: boolean): string;
setDefault(timezone?: string): MomentTimezone;
}
interface Moment {
tz(): string | undefined;
tz(timezone: string, keepLocalTime?: boolean): moment.Moment;
zoneAbbr(): string;
zoneName(): string;
}
const tz: MomentTimezone;
}
I will try import * as moment from 'moment-timezone';
I will try import * as moment from 'moment-timezone';
import moment from 'moment-timezone';
and
import * as moment from 'moment-timezone';
are the same if you enable allowSyntheticDefaultImports
in tsconfig.json
and it's not the cause of the error.
Can you share your tsconfig.json
? Don't you override --types
in compilerOptions
?
setDefault is part of current TS bindings, so it should work
Hello,
I know that moment.tz.setDefault('UTC') can be used to set default timezone, but in typescript i don't see tz property