final-form / final-form-calculate

Decorator for calculating field values based on other field values in 🏁 Final Form
MIT License
113 stars 26 forks source link

Version 1.3.2 lacks the type hint updates #47

Open eviltwin opened 3 years ago

eviltwin commented 3 years ago

Are you submitting a bug report or a feature request?

bug report/feature request/feature missing that shouldn't be missing?

What is the current behavior?

TypeScript types for createDecorator in v1.3.2 are missing the FormValues generic argument introduced by #39 . I can confirm that they're present when downloading the source bundle from the release on github, but downloading the package bundle from NPM shows them to be missing. The tag in github is correct, so I'm not sure how NPM didn't pick them up...

This is a frustrating issue right now, since the typings of react-final-form reject the unparameterised decorator's types as being incompatible with the parameterised Form's types, so we can't just use the typings as they stand (without suppressing the error).

What is the expected behavior?

The types introduced in #39 should have been in v1.3.2, as noted in the PR and the release notes.

At this point, I think the only path forwards is to tag a new release v1.3.3 that actually includes the types...

Sandbox Link

https://codesandbox.io/s/bold-bogdan-j4qh6?file=/src/App.tsx

What's your environment?

final-form-calculate: 1.3.2 final-form: 4.20.1

Other information

You can confirm that the types are not updated in the package published on NPM by grabbing its url like so:

$ npm view final-form-calculate@1.3.2

final-form-calculate@1.3.2 | MIT | deps: none | versions: 9
Decorator for calculating field values based on other field values in 🏁 Final Form
https://github.com/final-form/final-form-calculate#readme

dist
.tarball: https://registry.npmjs.org/final-form-calculate/-/final-form-calculate-1.3.2.tgz
.shasum: a5e1908d1aa34eeec6faccdba3fd9516e7fd3d4f
.integrity: sha512-pon2K9yNbyqmF8UTpDvxwhk+Hvqpl8Fm3qgwkHniNAmCQe+6YxB1aw4cBAHzmRc39jGl2bYsvKyabQOIWLtrPg==
.unpackedSize: 23.6 kB

maintainers:
- erikras <rasmussenerik@gmail.com>

dist-tags:
latest: 1.3.2

published 5 months ago by erikras <rasmussenerik@gmail.com>

Download the tarball, decompress it and view pacakge/dist/index.d.ts line 26, which lacks the generic type parameter:

export default function createDecorator(
  ...calculations: Calculation[]
): Decorator

Or by viewing the file on unpkg here: https://unpkg.com/browse/final-form-calculate@1.3.2/dist/index.d.ts

bartektartanus commented 3 years ago

Any progress on this issue?

youfoundron commented 3 years ago

would also benefit from this fix :)

iurietarlev commented 3 years ago

are there plans to publish/re-publish 1.3.2 with typing updates for typescript support?

twgraham commented 3 years ago

While we wait for a publish, you can add your own typings in a .d.ts file like so. Not ideal, but does the job.

import { Decorator } from 'final-form'

declare module 'final-form-calculate' {
    interface FFUpdatesByName<TFormValues> {
        [FieldName: string]: (value: any, allValues?: TFormValues, prevValues?: TFormValues) => any
      }

    type FFUpdatesForAll<TFormValues = object> = (
        value: any,
        field: string,
        allValues?: TFormValues,
        prevValues?: TFormValues,
    ) => { [FieldName: string]: any }

    type FFUpdates<TFormValues> = FFUpdatesByName<TFormValues> | FFUpdatesForAll<TFormValues>

    interface FFCalculation<TFormValues> {
        field: FieldPattern
        updates: FFUpdates<TFormValues>
        isEqual?: (a: any, b: any) => boolean
    }

    export default function createDecorator<TFormValues = object>(
        ...calculations: FFCalculation<TFormValues>[]
    ): Decorator<TFormValues>
}