Skip to content

Conversation

@I-Enderlord-I
Copy link

Fixed #15780

Summary

Actual fix for #15780 this time, rather than forcing an unsafe type cast as suggested in #15794.

Examples

See #15780 and for bad unsafe type cast think about:

interface IDoc {
  name: string;
}

interface DocStatics {
  m1(): void;
  m2(): void;
}

const schema = new Schema<IDoc, Model<IDoc>, {}, {}, {}, DocStatics>({});
schema.static({ m1(a: string) { console.log(a.slice(1)); } } } as DocStatics);

@I-Enderlord-I I-Enderlord-I changed the title Update queries.test.ts Fixed #15780 Nov 29, 2025
@I-Enderlord-I I-Enderlord-I changed the title Fixed #15780 Fixed #15780 by admitting calls to Schema.static with partial object Nov 29, 2025
@I-Enderlord-I I-Enderlord-I changed the title Fixed #15780 by admitting calls to Schema.static with partial object types(schema): fixed #15780 by admitting calls to Schema.static with partial object Nov 29, 2025
@I-Enderlord-I
Copy link
Author

I-Enderlord-I commented Nov 29, 2025

@vkarpov15
To your comment in #15786 which also relates to this here:

Making types more strict is only useful when the runtime is as strict as well. In this case, passing a partial object is deliberately allowed by the runtime code. If you do not like the types to allow that, you should change the JS code, not hinder corrections of the types.

As for using as to work around this: Doing type casts is never a soluion or even a workaround. It completely overrules the type checking and should only be done to silence errors which are known to be undesired behaviour. Even then, it's not safe to do so and needs to be thought about from the perspective of maintainability. Technically, every even remotely related type cast needs to be checked every time the code changes, because the argument why it was correct might no longer be valid.

Valid code that needs type casts to avoid errors is always an issue and excluding some long running TS design problems like the "correspondence problem" should be seen as a bug to be fixed by the developer responsible for the type.

@I-Enderlord-I
Copy link
Author

Also, don't forget that the same partial definition is already a thing for Schema.method. No one is complaining there and by symmetry, no one should here. There is no reason to treat statics different to methods.

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

Successfully merging this pull request may close these issues.

All methods required by TS when setting statics via Schema.static with object parameter

1 participant