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

Support "type" transformation #24

Closed
brxck opened this issue Jun 26, 2021 · 4 comments · Fixed by #32
Closed

Support "type" transformation #24

brxck opened this issue Jun 26, 2021 · 4 comments · Fixed by #32
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@brxck
Copy link
Collaborator

brxck commented Jun 26, 2021

Would it be possible to add a "type" transformation? In TypeScript, for example:

const logs: { user: string; event: string }[] = [];

I think being able to "take type" and select { user: string; event: string }[] it would be very useful.

Less important imo, but there are also the cases of generics and type parameters to consider?

@pokey
Copy link
Member

pokey commented Jun 27, 2021

Yep that's definitely doable

Can you elaborate on your comment re generics and type parameters?

@pokey pokey added the good first issue Good for newcomers label Jun 27, 2021
@pokey
Copy link
Member

pokey commented Jun 27, 2021

@pokey pokey added the enhancement New feature or request label Jun 27, 2021
@brxck
Copy link
Collaborator Author

brxck commented Jun 27, 2021

So I vaguely referred to those other things because I'm relatively new to TypeScript so I don't have strong opinions on how I'd like them to work.

Here's an example lifted from the TypeScript docs:

function identity<Type>(arg: Type): Type {
    return arg;
}

There's two different types related to the function:

  • the type variable <Type> — should it have its own transformation?
  • the return type Type — which I'd probably expect to be referenced by the "type" transformation

The type variable can appear again at call time, here it's <string>:

let output = identity<string>("myString");

@brxck
Copy link
Collaborator Author

brxck commented Jun 27, 2021

I'm unsure how the AST looks here & other details under the hood, but I would think that the "type" transformation should also cover type aliases and interface declarations.

type Point {
  x: number;
  y: number;
}

It would also be useful to reference properties of an object type similar to the way that the "map" transformation works on objects.


I'm starting to look into the implementation of this transformation -- no promises though!

@pokey pokey closed this as completed in #32 Jul 5, 2021
thetomcraig-aya pushed a commit to thetomcraig/cursorless that referenced this issue Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants