Skip to content

Commit

Permalink
minor TypeScript type fixes (date-fns#2844)
Browse files Browse the repository at this point in the history
  • Loading branch information
fturmel authored Jan 7, 2022
1 parent b091d16 commit 9730ce8
Show file tree
Hide file tree
Showing 27 changed files with 61 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/_lib/getUTCISOWeekYear/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import startOfUTCISOWeek from '../startOfUTCISOWeek/index'

// This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
export default function getUTCISOWeekYear(dirtyDate: Date | number) {
export default function getUTCISOWeekYear(dirtyDate: Date | number): number {
requiredArgs(1, arguments)

const date = toDate(dirtyDate)
Expand Down
2 changes: 1 addition & 1 deletion src/_lib/getUTCWeekYear/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import toInteger from '../toInteger/index'
export default function getUTCWeekYear(
dirtyDate: Date | number,
dirtyOptions?: LocaleOptions & FirstWeekContainsDateOptions & WeekStartOptions
) {
): number {
requiredArgs(1, arguments)

const date = toDate(dirtyDate)
Expand Down
2 changes: 1 addition & 1 deletion src/_lib/requiredArgs/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function requiredArgs(required: number, args: IArguments) {
export default function requiredArgs(required: number, args: IArguments): void {
if (args.length < required) {
throw new TypeError(
required +
Expand Down
3 changes: 2 additions & 1 deletion src/_lib/setUTCDay/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
/* eslint-env mocha */

import assert from 'assert'
import { Locale } from '../../locale/types'
import setUTCDay from '.'
import { Locale } from '../../locale/types'
import { Day } from '../../types'

describe('setUTCDay', () => {
it('sets the day of the week', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/_lib/startOfUTCWeek/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LocaleOptions, WeekStartOptions } from '../../types'
import toDate from '../../toDate/index'
import { LocaleOptions, WeekStartOptions } from '../../types'
import requiredArgs from '../requiredArgs/index'
import toInteger from '../toInteger/index'

Expand All @@ -8,7 +8,7 @@ import toInteger from '../toInteger/index'
export default function startOfUTCWeek(
dirtyDate: Date | number,
dirtyOptions?: LocaleOptions & WeekStartOptions
) {
): Date {
requiredArgs(1, arguments)

const options = dirtyOptions || {}
Expand Down
2 changes: 1 addition & 1 deletion src/_lib/startOfUTCWeekYear/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import toInteger from '../toInteger/index'
export default function startOfUTCWeekYear(
dirtyDate: Date | number,
dirtyOptions?: LocaleOptions & FirstWeekContainsDateOptions & WeekStartOptions
) {
): Date {
requiredArgs(1, arguments)

const options = dirtyOptions || {}
Expand Down
2 changes: 1 addition & 1 deletion src/_lib/test/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export function assertType<T>(_: T) {}
export function assertType<T>(_: T): void {}
2 changes: 1 addition & 1 deletion src/_lib/toInteger/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function toInteger(dirtyNumber: unknown) {
export default function toInteger(dirtyNumber: unknown): number {
if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
return NaN
}
Expand Down
1 change: 1 addition & 0 deletions src/areIntervalsOverlapping/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import toDate from '../toDate/index'
import { Interval } from '../types'
import requiredArgs from '../_lib/requiredArgs/index'

/**
Expand Down
5 changes: 3 additions & 2 deletions src/clamp/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import max from '../max'
import min from '../min'
import max from '../max/index'
import min from '../min/index'
import { Interval } from '../types'
import requiredArgs from '../_lib/requiredArgs/index'

/**
Expand Down
2 changes: 2 additions & 0 deletions src/clamp/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-env mocha */

import assert from 'assert'
import clamp from '.'

Expand Down
3 changes: 2 additions & 1 deletion src/eachMonthOfInterval/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import toDate from '../toDate/index'
import { Interval } from '../types'
import requiredArgs from '../_lib/requiredArgs/index'

/**
Expand Down Expand Up @@ -31,7 +32,7 @@ import requiredArgs from '../_lib/requiredArgs/index'
* // Fri Aug 01 2014 00:00:00
* // ]
*/
export default function eachMonthOfInterval(dirtyInterval: Interval) {
export default function eachMonthOfInterval(dirtyInterval: Interval): Date[] {
requiredArgs(1, arguments)

const interval = dirtyInterval || {}
Expand Down
1 change: 1 addition & 0 deletions src/eachQuarterOfInterval/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import addQuarters from '../addQuarters/index'
import startOfQuarter from '../startOfQuarter/index'
import toDate from '../toDate/index'
import { Interval } from '../types'
import requiredArgs from '../_lib/requiredArgs/index'

/**
Expand Down
4 changes: 2 additions & 2 deletions src/eachWeekOfInterval/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WeekStartOptions } from '../types'
import addWeeks from '../addWeeks/index'
import startOfWeek from '../startOfWeek/index'
import toDate from '../toDate/index'
import type { Interval, LocaleOptions, WeekStartOptions } from '../types'
import requiredArgs from '../_lib/requiredArgs/index'

/**
Expand Down Expand Up @@ -45,7 +45,7 @@ import requiredArgs from '../_lib/requiredArgs/index'
*/
export default function eachWeekOfInterval(
dirtyInterval: Interval,
options?: WeekStartOptions
options?: LocaleOptions & WeekStartOptions
): Date[] {
requiredArgs(1, arguments)

Expand Down
1 change: 1 addition & 0 deletions src/eachWeekendOfInterval/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import eachDayOfInterval from '../eachDayOfInterval/index'
import isSunday from '../isSunday/index'
import isWeekend from '../isWeekend/index'
import { Interval } from '../types'
import requiredArgs from '../_lib/requiredArgs/index'

/**
Expand Down
2 changes: 1 addition & 1 deletion src/eachYearOfInterval/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import requiredArgs from '../_lib/requiredArgs/index'
* // Sun Jan 01 2017 00:00:00
* // ]
*/
export default function eachYearOfInterval(dirtyInterval: Interval) {
export default function eachYearOfInterval(dirtyInterval: Interval): Date[] {
requiredArgs(1, arguments)

const interval = dirtyInterval || {}
Expand Down
1 change: 1 addition & 0 deletions src/formatDuration/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import defaultLocale from '../locale/en-US/index'
import { Locale } from '../locale/types'
import type { Duration } from '../types'

const defaultFormat: (keyof Duration)[] = [
Expand Down
1 change: 1 addition & 0 deletions src/formatISODuration/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Duration } from '../types'
import requiredArgs from '../_lib/requiredArgs/index'

/**
Expand Down
9 changes: 5 additions & 4 deletions src/intervalToDuration/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import compareAsc from '../compareAsc/index'
import differenceInYears from '../differenceInYears/index'
import differenceInMonths from '../differenceInMonths/index'
import differenceInDays from '../differenceInDays/index'
import differenceInHours from '../differenceInHours/index'
import differenceInMinutes from '../differenceInMinutes/index'
import differenceInMonths from '../differenceInMonths/index'
import differenceInSeconds from '../differenceInSeconds/index'
import differenceInYears from '../differenceInYears/index'
import isValid from '../isValid/index'
import requiredArgs from '../_lib/requiredArgs/index'
import toDate from '../toDate/index'
import sub from '../sub/index'
import toDate from '../toDate/index'
import { Duration, Interval } from '../types'
import requiredArgs from '../_lib/requiredArgs/index'

/**
* @name intervalToDuration
Expand Down
8 changes: 4 additions & 4 deletions src/setWeek/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import getWeek from '../getWeek/index'
import toDate from '../toDate/index'
import toInteger from '../_lib/toInteger/index'
import requiredArgs from '../_lib/requiredArgs/index'
import {
FirstWeekContainsDateOptions,
LocaleOptions,
WeekStartOptions,
FirstWeekContainsDateOptions,
} from '../types'
import requiredArgs from '../_lib/requiredArgs/index'
import toInteger from '../_lib/toInteger/index'

/**
* @name setWeek
Expand Down Expand Up @@ -55,7 +55,7 @@ import {
export default function setWeek(
dirtyDate: Date | number,
dirtyWeek: number,
options: LocaleOptions & WeekStartOptions & FirstWeekContainsDateOptions
options?: LocaleOptions & WeekStartOptions & FirstWeekContainsDateOptions
): Date {
requiredArgs(2, arguments)

Expand Down
2 changes: 1 addition & 1 deletion src/startOfTomorrow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* const result = startOfTomorrow()
* //=> Tue Oct 7 2014 00:00:00
*/
export default function startOfTomorrow() {
export default function startOfTomorrow(): Date {
const now = new Date()
const year = now.getFullYear()
const month = now.getMonth()
Expand Down
2 changes: 1 addition & 1 deletion src/startOfYesterday/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* const result = startOfYesterday()
* //=> Sun Oct 5 2014 00:00:00
*/
export default function startOfYesterday() {
export default function startOfYesterday(): Date {
const now = new Date()
const year = now.getFullYear()
const month = now.getMonth()
Expand Down
7 changes: 5 additions & 2 deletions src/subDays/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import toInteger from '../_lib/toInteger/index'
import addDays from '../addDays/index'
import requiredArgs from '../_lib/requiredArgs/index'
import toInteger from '../_lib/toInteger/index'

/**
* @name subDays
Expand All @@ -24,7 +24,10 @@ import requiredArgs from '../_lib/requiredArgs/index'
* const result = subDays(new Date(2014, 8, 1), 10)
* //=> Fri Aug 22 2014 00:00:00
*/
export default function subDays(dirtyDate: Date | number, dirtyAmount: number) {
export default function subDays(
dirtyDate: Date | number,
dirtyAmount: number
): Date {
requiredArgs(2, arguments)

const amount = toInteger(dirtyAmount)
Expand Down
7 changes: 5 additions & 2 deletions src/subHours/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import toInteger from '../_lib/toInteger/index'
import addHours from '../addHours/index'
import requiredArgs from '../_lib/requiredArgs/index'
import toInteger from '../_lib/toInteger/index'

/**
* @name subHours
Expand All @@ -24,7 +24,10 @@ import requiredArgs from '../_lib/requiredArgs/index'
* const result = subHours(new Date(2014, 6, 11, 1, 0), 2)
* //=> Thu Jul 10 2014 23:00:00
*/
export default function subHours(dirtyDate: Date | number, dirtyAmount: number) {
export default function subHours(
dirtyDate: Date | number,
dirtyAmount: number
): Date {
requiredArgs(2, arguments)

const amount = toInteger(dirtyAmount)
Expand Down
7 changes: 5 additions & 2 deletions src/subISOWeekYears/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import toInteger from '../_lib/toInteger/index'
import addISOWeekYears from '../addISOWeekYears/index'
import requiredArgs from '../_lib/requiredArgs/index'
import toInteger from '../_lib/toInteger/index'

/**
* @name subISOWeekYears
Expand Down Expand Up @@ -31,7 +31,10 @@ import requiredArgs from '../_lib/requiredArgs/index'
* const result = subISOWeekYears(new Date(2014, 8, 1), 5)
* //=> Mon Aug 31 2009 00:00:00
*/
export default function subISOWeekYears(dirtyDate: Date | number, dirtyAmount: number) {
export default function subISOWeekYears(
dirtyDate: Date | number,
dirtyAmount: number
): Date {
requiredArgs(2, arguments)

const amount = toInteger(dirtyAmount)
Expand Down
7 changes: 5 additions & 2 deletions src/subMilliseconds/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import toInteger from '../_lib/toInteger/index'
import addMilliseconds from '../addMilliseconds/index'
import requiredArgs from '../_lib/requiredArgs/index'
import toInteger from '../_lib/toInteger/index'

/**
* @name subMilliseconds
Expand All @@ -24,7 +24,10 @@ import requiredArgs from '../_lib/requiredArgs/index'
* const result = subMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
* //=> Thu Jul 10 2014 12:45:29.250
*/
export default function subMilliseconds(dirtyDate: Date | number, dirtyAmount: number) {
export default function subMilliseconds(
dirtyDate: Date | number,
dirtyAmount: number
): Date {
requiredArgs(2, arguments)

const amount = toInteger(dirtyAmount)
Expand Down
7 changes: 5 additions & 2 deletions src/subMinutes/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import toInteger from '../_lib/toInteger/index'
import addMinutes from '../addMinutes/index'
import requiredArgs from '../_lib/requiredArgs/index'
import toInteger from '../_lib/toInteger/index'

/**
* @name subMinutes
Expand All @@ -24,7 +24,10 @@ import requiredArgs from '../_lib/requiredArgs/index'
* const result = subMinutes(new Date(2014, 6, 10, 12, 0), 30)
* //=> Thu Jul 10 2014 11:30:00
*/
export default function subMinutes(dirtyDate: Date | number, dirtyAmount: number) {
export default function subMinutes(
dirtyDate: Date | number,
dirtyAmount: number
): Date {
requiredArgs(2, arguments)

const amount = toInteger(dirtyAmount)
Expand Down

0 comments on commit 9730ce8

Please sign in to comment.