1
I have the following dictionary in C#:
Dictionary<string, List<string>> ls = new Dictionary<string, List<string>>();
ls.Add("chave1", new List<string>());
ls['chave1'].Add("Valor adicionado");
I’m trying to create it like this in Typescript:
var dicionario:{[key:string]:string; [value:string[]:[]} = {}
dicionario['chave1'].push('Valor adicionado')
The above example of Typescript is not working, I tried it anyway, it seems that the above variable does not support two types in the same set {}
How can I make the same C# dictionary in Typescript?
Hello, I’m trying to create the C# dictionary of the question, the answer gave a clear, but did not solve the problem
– sYsTeM
Hi System, is there anything the object couldn’t do for you? What is the need to create a new structure if a native already exists and does the same job?
– Paz
I’m starting to learn Typescript , I can’t apply the example to the resolution.
– sYsTeM
it would help if you put some examples of how to put value in the key, check if there is value for that key and take the value with a specific key?
– Paz
That would help me a lot :)
– sYsTeM
@System show, I made a more elaborate example, put some comments in the middle of the code to help you understand
– Paz
It is in Javascript, how do I do the same in Typescript? It is because it is giving error of "Type"
– sYsTeM
@System can copy and paste the error here in the comment?
– Paz
That is the mistake: Element implicitly has an 'any' type because Expression of type '"key"' can’t be used to index type '{}'.
– sYsTeM
can post how the code looks? I’m sorry but I can’t emulate the same error in the typescript fiddle, follow the link to test. https://www.typescriptlang.org/play/? ssl=1&ssc=1&pln=27&pc=2#
– Paz