Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

how to get typescript duplicate property error?

$
0
0

I'm using typescript version 4.9.5 and i want to use an enum as keys of an object. for example:

enum TestEnum {  value1 = 'value1',  value2 = 'value2',}const variable: {[key in TestEnum]: number} = {  [TestEnum.value1]: 5,  [TestEnum.value2]: 7,  [TestEnum.value1]: 9,}

Problem is that in this version i wont get typescript duplicate property error. i know that in newer versions (> 5.1) it's handled. but i can't use another version.and i know if i use value1 instead of [TestEnum.value1] it will be handled by ts. but i don't want use enum value directly.Is there any other way to solve this problem?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>