Skip to content

Rename index to key for Map instances #776

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

Open
pimfm opened this issue Jan 18, 2022 · 1 comment
Open

Rename index to key for Map instances #776

pimfm opened this issue Jan 18, 2022 · 1 comment

Comments

@pimfm
Copy link

pimfm commented Jan 18, 2022

Good day, really enjoying your generator, thanks for the ease of use of this project. My colleagues found a small thing that could be improved:
This map

val explanations: Map<String, String>

is generated into this:

explanations: { [index: string]: string }

It would be really nice if this index name was actually 'key' to show the key/value relation.

I suspect this code has something to do with it, but am not familiar enough to offer you a pull reqest.

return (object: { [index: string]: T }) => __copyObject(object, itemCopyFn);

Hope you find the space to do this name adjustment. Thanks in advance

@vojtechhabarta
Copy link
Owner

Hello, actually it is mainly here:

public static class IndexedArrayType extends TsType {
public final TsType indexType;
public final TsType elementType;
public IndexedArrayType(TsType indexType, TsType elementType) {
this.indexType = indexType;
this.elementType = elementType;
}
@Override
public String format(Settings settings) {
return "{ [index: " + indexType.format(settings) + "]: " + elementType.format(settings) + " }";
}
}

This TypeScript feature is called Index Signatures (it was called Indexed Array in the past, I think) - https://www.typescriptlang.org/docs/handbook/2/objects.html#index-signatures. That's why there is usually index. But I agree that for many people key would be more clear.

It would be easy change but I am not sure.
There is also suggestion that Java Map should be generated as TypeScript Record (#706).

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

No branches or pull requests

2 participants