]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Export unitOfTime namespace
authorKilian Cirera Sant <kilianc@extrahop.com>
Fri, 12 Oct 2018 20:36:50 +0000 (13:36 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Fri, 24 Apr 2020 14:46:48 +0000 (17:46 +0300)
This allows developers to annotate variables as units of time.

Example:

```typescript
let unitOfTime: moment.unitOfTime.DurationConstructor = 'd';

// Here some code that might change unitOfTime
// ...

// TypeScript can make sure `unitOfTime` will have a valid value.
moment().add(x, unitOfTime);
```

moment.d.ts

index 2ceec4dfe8dccd988baaa5c9603db28f748291f6..9198eda6bd173d097169d68d5537a38a3e18f7d1 100644 (file)
@@ -197,7 +197,7 @@ declare namespace moment {
 
     toISOString(): string;
     toJSON(): string;
-    
+
     isValid(): boolean;
 
     /**
@@ -283,7 +283,7 @@ declare namespace moment {
 
   type MomentFormatSpecification = string | MomentBuiltinFormat | (string | MomentBuiltinFormat)[];
 
-  namespace unitOfTime {
+  export namespace unitOfTime {
     type Base = (
       "year" | "years" | "y" |
       "month" | "months" | "M" |
@@ -300,15 +300,15 @@ declare namespace moment {
     type _date = "date" | "dates" | "D";
     type DurationConstructor = Base | _quarter | _isoWeek;
 
-    type DurationAs = Base;
+    export type DurationAs = Base;
 
-    type StartOf = Base | _quarter | _isoWeek | _date | void; // null
+    export type StartOf = Base | _quarter | _isoWeek | _date | void; // null
 
-    type Diff = Base | _quarter;
+    export type Diff = Base | _quarter;
 
-    type MomentConstructor = Base | _date;
+    export type MomentConstructor = Base | _date;
 
-    type All = Base | _quarter | _isoWeek | _date |
+    export type All = Base | _quarter | _isoWeek | _date |
       "weekYear" | "weekYears" | "gg" |
       "isoWeekYear" | "isoWeekYears" | "GG" |
       "dayOfYear" | "dayOfYears" | "DDD" |
@@ -718,16 +718,16 @@ declare namespace moment {
 
   export var defaultFormat: string;
   export var defaultFormatUtc: string;
-  
-  export var HTML5_FMT: { 
+
+  export var HTML5_FMT: {
     DATETIME_LOCAL: string,
     DATETIME_LOCAL_SECONDS: string,
     DATETIME_LOCAL_MS: string,
-    DATE: string,                           
-    TIME: string,                                 
-    TIME_SECONDS: string,                      
-    TIME_MS: string,                        
-    WEEK: string,                           
+    DATE: string,
+    TIME: string,
+    TIME_SECONDS: string,
+    TIME_MS: string,
+    WEEK: string,
     MONTH: string
   };