0

It is possible to create custom user snippets in vs code. But is it possible to create them in detail for ts functions like:

someArray.forEach((val: getTypeFromArrayOnTheFly){

}

I did manage to create a basic snippet, but have no clue how to display it after writing an arrayName with dot. And also how to get the type from the array i want to use the snippet on.

1 Answer 1

2

Typescript Language Basics already defines the snippet foreach => which expands to

array.forEach(element => {
  
});

Since the type of array should be known, you don't need to define the type of element.

Sign up to request clarification or add additional context in comments.

3 Comments

its not only about forEach, its about snippets on to arrays. Also the type of the parameter is not set after the type of the array.
If you create an arrow function for a specific call of forEach, you don't need to annotate the arguments as their types are inferred. That's only useful if you define the consumer function somewhere else and reuse it. Same goes for other Array methods.
I have to work with lint rules, forcing me to define types. Thats why i search for ways to speed up the process and to not have to check and copy the types every time a write an array function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.