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

Improving FindOneOptions.relations typing #7134

Open
luisgurmendezMLabs opened this issue Dec 1, 2020 · 2 comments
Open

Improving FindOneOptions.relations typing #7134

luisgurmendezMLabs opened this issue Dec 1, 2020 · 2 comments

Comments

@luisgurmendezMLabs
Copy link

Feature Description

Improve Typescript definition

The Problem

The relations type of the FindOneOptions interface can be improved. Now it's represented by string[] and that is really annoying and prone to errors.

The Solution

Now that typescript 4.1 is out we can now define types as template literal string type https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html

So this gives us the advantage of making the nested objects properties as types!

I built up a quick example of how we can implement this:
https://www.typescriptlang.org/play?ts=4.1.2#code/JYOwLgpgTgZghgYwgAgIIBN1QgZxwbwFgAoZM5HMbCMALgqtAHMBuE85AGzjE5CfoAZHoP5tiAXxIlQkWIhTCwopkVJcewMAFd0EeiG0BbAEbRxZTgHt+W3fuSHT5klOIzw0eEmQBVHNBqHCBwRg6UUMwW5HCY2Hj0GFi4OOJuJGAAngAOKAAKkUZawABuKAC87MgAPgyR-FW1TmZQjcgmwEyybSZWVpwQcCBtOJmm-W2GnJxt2iB6MKAQ6OLSxFm5yABqcJzaEADyMAA8ACoAfMjlyKcA2gDWEJlWMDcAuqvrOSioCEh4ADlcJB0AUrLkoGBgLgtsA4AARKxgAFIzQ2M6Xa47PaHE74W55ZCgZCPZ6vU5veiEiAAD0g8xwdWYAH5kAAKO55N7IWn09CMgrAIpQsrIVmE+gAAwAJPg8hIAHSy37-HBAyjLMEQqEwuGI5GoqHozlvc4SSXIACUBggZSgEnOnw2KH80HVIK10B1jOuKpS7s1UHBXuhOFhCKRKLAaJAx1dUEdyAA9EnkAAiEJhNM1dOxZJ4BURCA0bO1NN5+I4BXcXj8auaHR6Uu5uIpeu1pjVmxdRsQNMkIA

If this is added as a type we could then change the relations type with string[] AccessNestedPropertiesViaDotNotation<Entity>

Considered Alternatives

An alternative can be a combination of what we remove here: 8cd8710#diff-91e84474846af2b18f59cff2ae65ec2c38001069b382885e40307aef68435658L21

so: relations?: ((keyof Entity) | string)[];

Are you willing to resolve this issue by submitting a Pull Request?

  • [x ] Yes, I have the time, and I know how to start.
    (If it's considered a good idea).
@nebkat
Copy link
Contributor

nebkat commented Dec 1, 2020

I've been doing some tests with this syntax, it will be very useful in future for all locations where property paths are used!

We will have to use something like downlevel-dts if we intend on maintaining backwards compatibility to users with older versions of TypeScript, since the template literal types won't be supported. I have mentioned it here #6810 (comment). Currently template literals aren't converted by downlevel-dts so that will also have to be implemented first.

@luisgurmendezMLabs
Copy link
Author

I didn't thought of the backwards compatibility, that is surely a problem. I guess till your comment #6810 (comment) isn't answered this will get blocked. Should I close this pr?

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

No branches or pull requests

2 participants