Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.3.2 lacks the type hint updates #47

Open
eviltwin opened this issue Feb 22, 2021 · 4 comments
Open

Version 1.3.2 lacks the type hint updates #47

eviltwin opened this issue Feb 22, 2021 · 4 comments

Comments

@eviltwin
Copy link

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 [email protected]

[email protected] | 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 <[email protected]>

dist-tags:
latest: 1.3.2

published 5 months ago by erikras <[email protected]>

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/[email protected]/dist/index.d.ts

@bartektartanus
Copy link

Any progress on this issue?

@youfoundron
Copy link

would also benefit from this fix :)

@iurietarlev
Copy link

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

@twgraham
Copy link

twgraham commented Aug 9, 2021

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>
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants