C
C#2y ago
enteleform

❔ Is there an equivalent feature to TypeScript's Indexed Access Types?

e.g.
type Example<T> = {
items: T[]
}

type StringItems = Example<string>["items"]
// string[]

function getStringItem(stringItems:StringItems){
// ...
}
type Example<T> = {
items: T[]
}

type StringItems = Example<string>["items"]
// string[]

function getStringItem(stringItems:StringItems){
// ...
}
4 Replies
ero
ero2y ago
I struggle to understand what this does. Doesn't this defeat the whole point of static typing?
Thinker
Thinker2y ago
Unfortunately C#'s type system is nowhere near as sophisticated as TypeScript's, so sadly this is not possible It's not possible to describe a type through other types like this.
enteleform
enteleform2y ago
It facilitates reuse of types rather than duplication. e.g. StringItems can be reused as many times as necessary, VS having to write Example<string>["items"] (or a much more complex type 💀) every time. More info @ https://www.typescriptlang.org/docs/handbook/2/indexed-access-types.html Gotcha, thanks for the info!
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
A series of errors (Install failed & Minimal hosting scenario!) while scaffolding for a ASP.NET CoreI followed this instruction to execute the ```API Controller with views, using Entity Framework``` h❔ InputDevices.GetDevicesWithCharacteristics doesnt exist??ive never gotten this error before, i dont know if i just havent imported something that i need to? ✅ How To Run CMD C WPFHow can I run a CMD command in the event handler of a button in C# WPF?❔ TCP Connect To Public iPI Make a simple app for chat(it work in local) but dos not work for connect to public IP❔ EmguCV with .NET MAUIHello everyone. I can access the camera with VideoCapture but I couldn't transfer it to Mat object✅ How to register all Automapper profiles from one project in the Startup class of a second projectHi friends, I have a solution with the structure in the screen-shot attachement, I use Automapper ❔ Doing freelance work. What is the right skill level to start it? Doing it to develop skills?Hello! I'm looking for some advice on this subject. I'm currently working on small projects to devel❔ Documentation on the AOT runtime's internal type system (EEType)?I'm trying to create my own operating system in C#, using the ZeroSharp repository (https://github.c❔ Page debugging twice in razor pages PageRouteModelConvention`public class CultureTemplatePageRouteModelConvention : IPageRouteModelConvention { public void ✅ What should I do now?Hello! I've watched a c# tutorial for beginners by freeCodeCamp.org which was 4 hours long. And now