adopted-ember-addons / ember-changeset

Ember.js flavored changesets, inspired by Ecto
http://bit.ly/ember-changeset-demo
MIT License
431 stars 141 forks source link

Missing types in index.d.ts #625

Open bartocc opened 2 years ago

bartocc commented 2 years ago

It is great to have a type definitions file index.d.ts, but it looks like it has not been updated since a long time and is now quite incomplete.

In our codebase, we often use the imports listed below and they generate TS errors.

Version

3.15.0

Steps to reproduce

Add the following imports in a *.ts file

import { Changeset } from "ember-changeset";
import { EmberChangeset } from "ember-changeset";

Expected Behavior

No TS error

Actual Behavior

Module '"ember-changeset"' has no exported member 'Changeset'. Module '"ember-changeset"' has no exported member 'EmberChangeset'.

snewcomer commented 2 years ago

Thx! And you are right. Would you be up for putting together a pr?

bartocc commented 2 years ago

Yes, definitely

I am a bit confused though… there are 2 type definition files

The later is more complete than the former

Do they serve different purposes or are they duplicates?

bartocc commented 2 years ago

@snewcomer could you help me understand why these 2 definition files exist?

The way I see it, they could/should be merged… but I might be missing something…

Thx

snewcomer commented 2 years ago

Seems like they could in index.d.ts

https://github.com/poteto/ember-changeset/blob/master/package.json#L21

azhiv commented 2 years ago

It would also be great to add correct typings for Changeset function, namely its last parameter - option, since the addon supports passing a custom changeset class into it:

if (options.changeset) {
  return new options.changeset(obj, validateFn, validationMap, options);
}

Current definition only exposes two keys for the hash:

export type Config = {
  skipValidate?: boolean;
  changesetKeys?: string[];
};
bartocc commented 2 years ago

PR https://github.com/poteto/ember-changeset/pull/635 just did this @azhiv

azhiv commented 2 years ago

Ok, cool! Looking forward to get a fresh release with all the changes.