Nightapes / HumanizeDuration.ts

361000 becomes "6 minutes, 1 second"
The Unlicense
24 stars 5 forks source link

Typescript warning when using HumanizeDuration #19

Open tomers opened 3 years ago

tomers commented 3 years ago
import { HumanizeDuration } from 'humanize-duration-ts'

...
const durationStr: string = HumanizeDuration(1000)

The above code results in the following error:

@typescript-eslint/no-unsafe-assignment: Unsafe assignment of an any value.

Version:

humanize-duration-ts@^2.1.1:
  version "2.1.1"
  resolved "https://registry.yarnpkg.com/humanize-duration-ts/-/humanize-duration-ts-2.1.1.tgz#5382b2789f851005a67229eaf031931d71f37ee9"
  integrity sha512-TibNF2/fkypjAfHdGpWL/dmWUS0G6Qi+3mKyiB6LDCowbMy+PtzbgPTnFMNTOVAJXDau01jYrJ3tFoz5AJSqhA==
tomers commented 3 years ago

Oh, I guess I haven't RTFM it...

import { HumanizeDurationLanguage, HumanizeDuration } from 'humanize-duration-ts'

const langService: HumanizeDurationLanguage = new HumanizeDurationLanguage()
const humanizer = new HumanizeDuration(langService)

...
const durationStr: string = humanizer.humanize(1000)

Maybe turn this issue into a feature request to support a short notation, i.e. to allow writing the above code in the abbreviated form of (assuming default language):

import { HumanizeDuration } from 'humanize-duration-ts'

...
const durationStr: string = HumanizeDuration(1000)