Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ajmas opened this issue Sep 16, 2021 · 8 comments

Comments

@ajmas
Copy link

ajmas commented Sep 16, 2021

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

  • countries-and-timezones: 3.2.2
  • nodejs: v14.15.1
  • typescript: 3.9.5

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
Copy link

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

@oldschoolbg
Copy link

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
Copy link
Owner

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
Copy link
Author

ajmas commented Sep 29, 2021

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

@oldschoolbg
Copy link

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

@manuelmhtr
Copy link
Owner

Closing this issue assuming it's fixed.

@ajmas
Copy link
Author

ajmas commented Oct 19, 2021

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

@oldschoolbg
Copy link

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants