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

fix: generic type for getDataValue #346

Merged
merged 3 commits into from
Sep 21, 2022

Conversation

vagusX
Copy link
Collaborator

@vagusX vagusX commented Sep 21, 2022

No description provided.

@vagusX vagusX changed the title fix: type for getDataValue fix: generic type for getDataValue Sep 21, 2022
src/adapters/sequelize.d.ts Outdated Show resolved Hide resolved
@vagusX vagusX requested a review from cyjake September 21, 2022 08:06
setDataValue(key: string, value: Literal | Literal[]): void;
getDataValue(key?: string): Literal | { [key: string]: Literal };
setDataValue<T, Key extends keyof T>(this: T, key: Key, value: T[Key]): void;
getDataValue<T>(this: T): T;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

啊?这样不对吧?

是不是没办法 getDataValue<T>(this: T, key: string): T[key] 这样

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overload 没问题啊,本身不传值返回的就是 this,传值就是 this[key] 👇

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看懂啦,会不会有点太麻烦了😂

你们模型层切换到 ts 了没,已经切换的话,this.getDataValue<User['id']> 可以用 this.id 平替呀

@cyjake cyjake merged commit 00bbaf4 into cyjake:master Sep 21, 2022
@vagusX vagusX deleted the fix/type-for-getDataValue branch September 21, 2022 09:01
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.

2 participants