You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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?
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?
(If it's considered a good idea).
The text was updated successfully, but these errors were encountered: