Merged
Conversation
Pull Request Test Coverage Report for Build 9732452201Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9797301066Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9817607131Details
💛 - Coveralls |
SukkaW
previously approved these changes
Jul 6, 2024
Pull Request Test Coverage Report for Build 9819663515Details
💛 - Coveralls |
D-Sketon
commented
Jul 6, 2024
| Document: { new<T>(data: T): Document<T> }; | ||
| Query: { new<T>(data: Document<T>[]): Query<T> }; | ||
| _database: Database; | ||
| [key : string]: any; |
Member
Author
Member
Author
There was a problem hiding this comment.
I was going to add another generic for setting the type of static and method, but its not possible to act directly on the class.
interface Extra {
statics: Record<string, (...args: any[]) => any>;
methods: Record<string, (...args: any[]) => any>;
}
type AddThis<R extends Record<string, (...args: any[]) => any>, T> = {
[K in keyof R]: (this: T, ...args: Parameters<R[K]>) => ReturnType<R[K]>;
}
class Schema<T = any, K extends Partial<Extra> = Extra> {
statics!: K['statics'] extends Record<string, (...args: any[]) => any> ? AddThis<K['statics'], T> : Record<string, (this: T, ...args: any[]) => any>;
methods!: K['methods'] extends Record<string, (...args: any[]) => any> ? AddThis<K['methods'], T> : Record<string, (this: T, ...args: any[]) => any>;
}
interface AssetSchema {
_id: string
}
const a = new Schema<AssetSchema, {
statics: {
add: (a: number, b: number) => number;
}
}>().statics.add // <-- (this: AssetSchema, a: number, b: number) => ReturnType<(a: number, b: number) => number>
const b = new Schema<AssetSchema>().methods // <-- AddThis<Record<string, (...args: any[]) => any>, AssetSchema>
class Model<T, K extends Partial<Extra> = Extra> {
schema!: Schema<T, K>
// [key in keyof K['statics']]: K['statics'][key] illegal
}
Member
There was a problem hiding this comment.
I have some vague ideas about this:
- We can modify the
Schematype so thatvirtual(and others) will "concat" the type information and return the newSchematype.- A similar implementation can be found here, where
@commander-js/extra-typingsallowscommand.option().option().option().option()to be typed: https://github.com/commander-js/extra-typings/blob/e53229bf91e73df4a1b5b6be3ef39b1737397b63/index.d.ts#L938-L957
- A similar implementation can be found here, where
- With the new
SchematypeModelshould be able toinferthe methods.
We can do this in another PR.
Pull Request Test Coverage Report for Build 12721566187Details
💛 - Coveralls |
uiolee
reviewed
Jan 9, 2025
Member
|
Conflicts with branch master's code, could you update them? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
now