manuelmhtr / countries-and-timezones

Minimalistic library to work with countries and timezones data
MIT License
220 stars 68 forks source link

Typescript error: `A 'const' initializer in an ambient context must be a string or...` #41

Closed ajmas closed 2 years ago

ajmas commented 2 years ago

When building a typescript based project using countries-and-timezone as a dependency, I get the following error:

node_modules/countries-and-timezones/esm/types.d.ts:2:25 - error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.

With the following output displayed (truncated):

declare const countries={AD:"Andorra",AE:"United Arab Emirates",AF:"Afghanistan",AG:"Antigua and Barbuda",AI:"Anguilla",AL:"Albania",AM:"Armenia",AO:"Angola",AQ:"Antarctica",AR:"Argentina",AS:"American Samoa",AT:"Austria",AU:"Australia",AW:"Aruba",AX:"Åland Islands",AZ:"Azerbaijan",BA:"Bosnia and Herzegovina",BB:"Barbados",BD:"Bangladesh",BE:"Belgium",BF:"Burkina Faso",BG:"Bulgaria",BH:"Bahrain",BI:"Burundi",BJ:"Benin",BL:"Saint Barthélemy",BM:"Bermuda",BN:"Brunei",BO:"Bolivia",BQ:"Caribbean Netherlands",BR:"Brazil",BS:"Bahamas",BT:"Bhutan",BV:"Bouvet Island",BW:"Botswana",BY:"Belarus",BZ:"Belize",CA:"Canada",CC:"Cocos Islands",CD:"Democratic Republic of the Congo",CF:"Central African Republic",CG:"Republic of the Congo",CH:"Switzerland",CI:"Ivory Coast",CK:"Cook Islands",CL:"Chile",CM:"Cameroon",CN:"China",CO:"Colombia",CR:"Costa Rica",CU:"Cuba",CV:"Cabo Verde",CW:"Curaçao",CX:"Christmas Island",CY:"Cyprus",CZ:"Czechia",DE:"Germany",DJ:"Djibouti",DK:"Denmark",DM:"Dominica",DO:"Dominican Republic",DZ:"Algeria",EC:"Ecuador",EE:"Estonia",EG:"Egypt",EH:"Western Sahara",ER:"Eritrea",ES:"Spain",ET:"Ethiopia",FI:"Finland",FJ:"Fiji",FK:"Falkland Islands",FM:"Micronesia",FO:"Faroe Islands",FR:"France",GA:"Gabon",GB:"United Kingdom",GD:"Grenada",GE:"Georgia",GF:"French Guiana",GG:"Guernsey",GH:"Ghana",GI:"Gibraltar",GL:"Greenland",GM:"Gambia",GN:"Guinea",GP:"Guadeloupe",GQ:"Equatorial Guinea",GR:"Greece",GS:"South Georgia and the South Sandwich Islands",GT:"Guatemala",GU:"Guam",GW:"Guinea-Bissau",GY:"Guyana",HK:"Hong Kong",HM:"Heard Island and McDonald Islands",HN:"Honduras",HR:"Croatia",HT:"Haiti",HU:"Hungary",ID:"Indonesia",IE:"Ireland",IL:"Israel",IM:"Isle of Man",IN:"India",IO:"British Indian Ocean Territory",IQ:"Iraq",IR:"Iran",IS:"Iceland",IT:"Italy",JE:"Jersey",JM:"Jamaica",JO:"Jordan",JP:"Japan",KE:"Kenya",KG:"Kyrgyzstan",KH:"Cambodia",KI:"Kiribati",KM:"Comoros",KN:"Saint Kitts and Nevis",KP:"North Korea",KR:"South Korea",KW:"Kuwait",KY:"Cayman Islands",KZ:"Kazakhstan",LA:"Laos",LB:"Lebanon",LC:"Saint Lucia",LI:"Liechtenstein",LK:"Sri Lanka",LR:"Liberia",LS:"Lesotho",LT:"Lithuania",LU:"Luxembourg",LV:"Latvia",LY:"Libya",MA:"Morocco",MC:"Monaco",MD:"Moldova",ME:"Montenegro",MF:"Saint Martin",MG:"Madagascar",MH:"Marshall Islands",MK:"North Macedonia",ML:"Mali",MM:"Myanmar",MN:"Mongolia",MO:"Macao",MP:"Northern Mariana Islands",MQ:"Martinique",MR:"Mauritania",MS:"Montserrat",MT:"Malta",MU:"Mauritius",MV:"Maldives",MW:"Malawi",MX:"Mexico",MY:"Malaysia",MZ:"Mozambique",NA:"Namibia",NC:"New Caledo

Looking at the explanation of this error and looking at esm/index.d.ts, it would seem lines 1 & 2 are problematic, since they are complex types.

Workaround

Install 3.1.0 of countries-and-timezones, since all of the 3.2.x versions cause the same issue.

Versions

BTW I don't see a 3.2.2 tag or release in this repository, even if changes and npm make reference to it - is that an omission?

oldschoolbg commented 2 years ago

I just came here to report this as well. Glad to see the work around, thanks for that.

oldschoolbg commented 2 years ago

I don't know if this helps however I have managed to get 3.2.2 working and compiling (I had other issues with 3.1.0)

https://stackoverflow.com/questions/65543585/a-const-initializer-in-an-ambient-context-must-be-a-string-or-numeric-literal

If you see above if you add the skipLibCheck then it compiles for me.

manuelmhtr commented 2 years ago

Hi @ajmas @oldschoolbg, sorry for the late reply.

I think it's fixed in version v3.2.3, could you try it?

I also pushed the missing tag for v3.2.2. Thanks for your help.

ajmas commented 2 years ago

I won’t be able to check this until Monday, due to lack of access to my computer.

oldschoolbg commented 2 years ago

thanks for getting this looked at @manuelmhtr I will endeavour to check this out either this evening or tomorrow morning.

manuelmhtr commented 2 years ago

Closing this issue assuming it's fixed.

ajmas commented 2 years ago

Only just got around to testing this. The issue does appear to be resolved - thanks. Tested with 3.3.0

oldschoolbg commented 2 years ago

Oh I got SO busy with "paid" work I've not been back to my private project that was using this :)

Great news, thanks so much for getting this resolved :) I'll test it as well asap but good news from @ajmas that it works :)