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

feat(ts): add generic to mapper #338

Merged
merged 4 commits into from Oct 8, 2019

Conversation

koriwi
Copy link
Contributor

@koriwi koriwi commented Sep 26, 2019

may i propose these changes?
I modified the DefinetlyTyped typings before and used them with 100% success.
Tried to port them to your official typings now.

@jorgebay
Copy link
Contributor

I think its a great idea!

To prevent breaking changes, we should introduce new interfaces instead of modifying existing ones.

Introduce a new ModelMapperGeneric<T> (nvm the name), that contains all the properties:

interface ModelMapperGeneric<T> {
  get(doc: T, docInfo?: { fields?: string[] }, executionOptions?: string | MappingExecutionOptions): Promise<T>;
  //...
}

Make ModelMapper extend ModelMapperGeneric<any>:

interface ModelMapper extends ModelMapperGeneric<any> {
}

Create an overload of forModel() (one generic and the other leave as is):

  forModel(name: string): ModelMapper;

  forModel<T>(name: string): ModelMapperGeneric<T>;

lib/mapping/index.d.ts Outdated Show resolved Hide resolved
@jorgebay
Copy link
Contributor

I've created a ticket to track this: https://datastax-oss.atlassian.net/browse/NODEJS-562

@koriwi
Copy link
Contributor Author

koriwi commented Oct 6, 2019

Have you read my answer about any or { [key: string]: any } ?

Copy link
Contributor

@jorgebay jorgebay left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time of explaining TypeScript concepts to me.

I've noticed a mismatch between ModelMapper<T>#get() and Result#first()` regarding null type.

lib/mapping/index.d.ts Show resolved Hide resolved
@jorgebay jorgebay merged commit a37b9a7 into datastax:master Oct 8, 2019
@jorgebay
Copy link
Contributor

jorgebay commented Oct 8, 2019

Landed in a37b9a7, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants