pinia-orm icon indicating copy to clipboard operation
pinia-orm copied to clipboard

Enhancing typescript safety in model class by removing generic property declaration

Open joris-gallot opened this issue 1 year ago • 3 comments

Environment

No response

Reproduction

I don't think we need a reproduction link for this

Describe the bug

The Model class has this line [s: keyof ModelFields]: any;, which I think is problematic because it allows us to use any property of the model without typescript errors. I think we should remove this line. Is there a specific reason for keeping it?

For example for this Foo model, we should get this ts error: Property 'bar' does not exist on type 'Foo'..., while in the example, bar is typed as any

export class Foo extends Model {
  @Uid() id!: number;
}

const foo = new Foo();
foo.bar; //  typed as any

Current behavior Capture d’écran 2024-01-10 à 10 13 36

Expected behavior Capture d’écran 2024-01-10 à 10 13 54

Additional context

I'm putting this issue here for discussion, but I can tackle this task if needed 😁

Logs

No response

joris-gallot avatar Jan 10 '24 09:01 joris-gallot

Good Question. I don't know yet. I am not a typescript pro. I try to play with your idea to see if maybe i get any caveats.

CodeDredd avatar Jan 18 '24 10:01 CodeDredd

Thank you! I've already quickly tested removing that line to see if there was anything blocking, and I didn't find anything special. If you need help with that, I'd be happy to offer a PR when I have some time 😁

joris-gallot avatar Jan 18 '24 10:01 joris-gallot

I would also love this feature, as I expected the default behavior to be more strict.
Maybe It's something that could be toggled via a config prop?

daniandl avatar Jan 18 '24 16:01 daniandl

@joris-gallot @daniandl Well guys its your lucky day. You are getting more than that 😉

CodeDredd avatar May 06 '24 09:05 CodeDredd