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

Autocomplete when typing lens #2

Open
michaelKurowski opened this issue Aug 4, 2023 · 4 comments
Open

Autocomplete when typing lens #2

michaelKurowski opened this issue Aug 4, 2023 · 4 comments

Comments

@michaelKurowski
Copy link

michaelKurowski commented Aug 4, 2023

I know that this solution is already based on a likely tricky implementation of free types, but is it possible to have autocomplete when typing lens directly inside a focusing generic i.e. Get?

Get<
  ['have', 'autocomplete', 'here', 'since', 'we', 'know', 'the', 'target', 'type'],
  MyType
>

That is if MyType already has MyType['have']['autocomplete']['here']... it could be autocompleted when using needle in the Get generic.

@geoffreytools
Copy link
Owner

geoffreytools commented Aug 4, 2023

Hi,

The only way I can imagine implementing this would be to create a type definition from Haystack with a union of every possible path. This would likely tank performance.

However, if I implement type checking on Lens as mentioned in #1 then you could trigger suggestions for valid paths by typing a wrong path.

type Model = { a: number, b: [ {c: number}, {d: number} ] }
type Query = Lens<['b', unknown], Model>
//                ~~~~~~~~~~~~~
// Type '["b", unknown]' does not satisfy the constraint '["b", 0] | ["b", 1]'

I would not need to go deeper than one level after 'b'

@geoffreytools
Copy link
Owner

geoffreytools commented Aug 4, 2023

Hum I actually tried a dummy interface with an exhaustive union of paths and you wouldn't get auto-completion with this. You would get suggestions in a very noisy tooltip but not an interactive list, at least in VS Code. I don't think this is something under my control.

Programming with a whole would be a little more helpful: you can start with Lens<[''], Model>, be prompted to try ['a' | 'b'], then Lens<['b', ''], Model>, be prompted to try ["b", 0 | 1], etc.

@michaelKurowski
Copy link
Author

Hi,
it is a bit suboptimal in comparison to the autocomplete, but it's a big QoL improvement. When using this feature then by definition you operate on complex objects and any form of a hint as you type is very helpful. Thanks!

@geoffreytools
Copy link
Owner

geoffreytools commented Aug 7, 2023

You may be interested in FindPaths for quickly coming up with a path. It's been added to the latest version. I updated the readme.

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