question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support an array of names

See original GitHub issue

Could we have support for an array of values that returns an array.

e.g.

myProperties: string[] = nameof<Company>(o => o.Name, o => o.Address1, o => o.Address2);

transpiles to:

myProperties = ["Name", "Address1", "Address2"];

Maybe even call it namesOf?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dsherretcommented, Jul 3, 2019

This is merged and available now thanks to @cecilyth!


One important thing to note is that the following transform is not yet available…

nameof.toArray<SomeInterface, OtherInterface, SomeType>();

… we’ll have to wait for TypeScript to support calling functions with a variable number of type arguments (ex. nameof.toArray<...T>(): string[]). A workaround would be to just add a bunch of function declarations with different number of type arguments (ex. nameof.toArray<T1>(): string[]; nameof.toArray<T1, T2>(): string[]; ...etc...). Might be worth it to do that actually.

Perhaps it would also be good to implement something like nameof.toArray<T1, T2>((o1, o2) => [o1.test, o2.asdf]); and with more type parameters.

Anyway, something to think about for improving this. Please let me know if you would like any of these features.

1reaction
dsherretcommented, Dec 14, 2018

Interesting idea. Perhaps the following?

nameof.toArray<Company>(o => [o.Name, o.Address1, o.Address2]);

Signatures:

function toArray<T>(func: (obj: T) => any[]): string[];
function toArray(...args: any[]): string[];
Read more comments on GitHub >

github_iconTop Results From Across the Web

Name an array constant - Microsoft Support
To name an array constant, click Formula, then Define Name. Enter a name and the constant, then you can use the constant as...
Read more >
How to pass an array within a query string? - Stack Overflow
I want that query string value to be treated as an array- I don't want the array to be exploded so that it...
Read more >
Array - JavaScript - MDN Web Docs
The Array object, as with arrays in other programming languages, enables storing a collection of multiple items under a single variable name ......
Read more >
Work with arrays | BigQuery - Google Cloud
With Google Standard SQL, you can construct array literals, build arrays from subqueries using the ARRAY function, and aggregate values into an array...
Read more >
JavaScript Arrays - W3Schools
Many programming languages support arrays with named indexes. Arrays with named indexes are called associative arrays (or hashes). JavaScript does not support ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found