Menu

TypeScript 7.1 Beta: Import Attributes in Ambient Modules
📰

TypeScript 7.1 Beta: Import Attributes in Ambient Modules

DEV Community: javascript·Qasim Parray·3 days ago
#yGpcgWRu
#devtojavascript#devto#dev#type#import
Reading 0:00
15s threshold

I have a file called globals.d.ts in more projects than I'd like to admit. It started life as three lines for *.css imports, and over time it picked up *.svg , *.md , *.txt and one cursed *.sql entry that I'm fairly sure nobody has touched since it was written. Every new repo, I copy it over without reading it. It works, so I never look at it.

Then I read the TypeScript 7.1 beta announcement and the first feature on the list made me open that file and wince. Ambient module declarations can now carry import attributes. That sounds like a tiny change. It isn't, because it quietly fixes a lie that wildcard declarations have been telling for years.

Short version for the impatient: if your project imports CSS, text or binary files, 7.1 lets you declare the type per import attribute instead of per file extension, and the compiler will complain when you forget the attribute.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.