<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Loïc Sapone</title>
    <description>The latest articles on DEV Community by Loïc Sapone (@loicsapone).</description>
    <link>https://dev.to/loicsapone</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4246297%2F7987f956-e2f0-438e-9de6-e172eb405213.jpg</url>
      <title>DEV Community: Loïc Sapone</title>
      <link>https://dev.to/loicsapone</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/loicsapone"/>
    <language>en</language>
    <item>
      <title>AssetMapper and TypeScript: getting the missing types with a Symfony bundle</title>
      <dc:creator>Loïc Sapone</dc:creator>
      <pubDate>Sat, 28 Nov 2026 14:00:09 +0000</pubDate>
      <link>https://dev.to/loicsapone/assetmapper-and-typescript-getting-the-missing-types-with-a-symfony-bundle-51m8</link>
      <guid>https://dev.to/loicsapone/assetmapper-and-typescript-getting-the-missing-types-with-a-symfony-bundle-51m8</guid>
      <description>&lt;p&gt;AssetMapper simplifies asset management in Symfony, but it doesn't download TypeScript types. Your IDE knows nothing about the JS libraries you use, everything is an implicit &lt;code&gt;any&lt;/code&gt;, and type errors slip through the cracks.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: AssetMapper doesn't download types
&lt;/h2&gt;

&lt;p&gt;With npm, when you install a dependency, you get the entire package: the sources, the TypeScript declaration files (&lt;code&gt;.d.ts&lt;/code&gt;), the metadata. TypeScript knows where to look for types, and the IDE follows.&lt;/p&gt;

&lt;p&gt;AssetMapper works differently. It only downloads the JS file exposed by the package, which is enough for execution, but not for type checking. The &lt;code&gt;.d.ts&lt;/code&gt; files are not part of the downloaded bundle.&lt;/p&gt;

&lt;p&gt;Direct consequence: TypeScript and IDEs like VSCode or PhpStorm find no type definitions for your imports. Everything is an implicit &lt;code&gt;any&lt;/code&gt;. Type errors go undetected and autocompletion doesn't work.&lt;/p&gt;

&lt;h2&gt;
  
  
  How TypeScript resolves types
&lt;/h2&gt;

&lt;p&gt;Before looking for a solution, you need to understand the resolution mechanism.&lt;/p&gt;

&lt;p&gt;A JS package can ship its own type definitions through a &lt;code&gt;types&lt;/code&gt; or &lt;code&gt;typings&lt;/code&gt; field in its &lt;code&gt;package.json&lt;/code&gt;. This field points to a root &lt;code&gt;.d.ts&lt;/code&gt; file, which can itself import other declaration files. This graph of files is what TypeScript walks to resolve types at compile time.&lt;/p&gt;

&lt;p&gt;In a standard npm project, all of that lives in &lt;code&gt;node_modules&lt;/code&gt;. TypeScript knows to look there by default. Without &lt;code&gt;node_modules&lt;/code&gt;, you have to tell it explicitly where to look. That's the role of the &lt;code&gt;paths&lt;/code&gt; config in &lt;code&gt;tsconfig.json&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"compilerOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"paths"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"@hotwired/stimulus"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"./assets/vendor/@hotwired/stimulus/dist/types/index.d.ts"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;paths&lt;/code&gt; maps an import identifier (like &lt;code&gt;@hotwired/stimulus&lt;/code&gt;) to one or more local paths. TypeScript goes through them in order until it finds a match.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The manual solution
&lt;/h2&gt;

&lt;p&gt;The procedure is simple, but tedious to do by hand for every package.&lt;/p&gt;

&lt;p&gt;First step: identify whether the package exposes types. Look at its &lt;code&gt;package.json&lt;/code&gt; on jsDelivr or npm, and search for the &lt;code&gt;types&lt;/code&gt; or &lt;code&gt;typings&lt;/code&gt; field.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://cdn.jsdelivr.net/npm/@hotwired/stimulus/package.json &lt;span class="o"&gt;|&lt;/span&gt; jq &lt;span class="s1"&gt;'.types'&lt;/span&gt;
&lt;span class="c"&gt;# → "dist/types/index.d.ts"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Second step: fetch the root &lt;code&gt;.d.ts&lt;/code&gt; file, then every imported file recursively. A declaration file can import others through relative paths: you need to download them all for resolution to work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Fetch the root file&lt;/span&gt;
curl -o assets/vendor/@hotwired/stimulus/dist/types/index.d.ts \
  https://cdn.jsdelivr.net/npm/@hotwired/stimulus/dist/types/index.d.ts

&lt;span class="c"&gt;# Fetch the referenced files&lt;/span&gt;
curl -o assets/vendor/@hotwired/stimulus/dist/types/core.d.ts \
  https://cdn.jsdelivr.net/npm/@hotwired/stimulus/dist/types/core.d.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Third step: update &lt;code&gt;tsconfig.json&lt;/code&gt; with the matching &lt;code&gt;paths&lt;/code&gt; entry.&lt;/p&gt;

&lt;p&gt;This procedure works. We validated it on several packages. But it doesn't scale: every &lt;code&gt;importmap:require&lt;/code&gt;, you start over. And if a package updates its types, you have no way of knowing.&lt;/p&gt;

&lt;h2&gt;
  
  
  TypescriptTypesBundle: automating all of this
&lt;/h2&gt;

&lt;p&gt;To avoid repeating this procedure by hand, we built &lt;code&gt;IQ2i/typescript-types-bundle&lt;/code&gt;. The idea is simple: read &lt;code&gt;importmap.php&lt;/code&gt;, detect the packages that expose types, download the &lt;code&gt;.d.ts&lt;/code&gt; files, and update &lt;code&gt;tsconfig.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Installation goes through Composer, as a development dependency: the bundle is only IDE tooling, nothing is needed in production.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require --dev iq2i/typescript-types-bundle
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once installed, a single command is enough to synchronize the types of every package declared in the importmap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php bin/console typescript:types:download
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The bundle queries jsDelivr to fetch each package's &lt;code&gt;package.json&lt;/code&gt;, checks for a &lt;code&gt;types&lt;/code&gt; or &lt;code&gt;typings&lt;/code&gt; field, downloads all the package's &lt;code&gt;.d.ts&lt;/code&gt; files into &lt;code&gt;assets/vendor/@types/&lt;/code&gt;, then updates &lt;code&gt;tsconfig.json&lt;/code&gt;. The &lt;code&gt;paths&lt;/code&gt; point to each package's folder, not to a specific file: it's the &lt;code&gt;types&lt;/code&gt; field of the downloaded &lt;code&gt;package.json&lt;/code&gt; that tells TypeScript the entry point. Here is what that looks like on a project with Stimulus and Tom Select:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"compilerOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"paths"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"@hotwired/stimulus"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"./assets/vendor/@types/@hotwired/stimulus"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"tom-select"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"./assets/vendor/@types/tom-select"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if a package doesn't declare a &lt;code&gt;types&lt;/code&gt; field? The bundle doesn't stop there: it looks for the matching &lt;code&gt;@types/*&lt;/code&gt; package on DefinitelyTyped, as npm would. A package like &lt;code&gt;lodash&lt;/code&gt;, which doesn't ship its own declarations, still gets its types through &lt;code&gt;@types/lodash&lt;/code&gt;. If nothing exists on the DefinitelyTyped side either, the package is skipped without error.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The bundle only touches the &lt;code&gt;paths&lt;/code&gt; section. If &lt;code&gt;tsconfig.json&lt;/code&gt; already exists, only the missing entries are added, the rest is preserved. If it doesn't exist, it is created.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The result is visible immediately in the editor: autocompletion on imports, method signatures, type errors flagged as you type.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give it a try!
&lt;/h2&gt;

&lt;p&gt;The bundle is open source and available on GitHub: &lt;a href="https://github.com/IQ2i/typescript-types-bundle" rel="noopener noreferrer"&gt;IQ2i/typescript-types-bundle&lt;/a&gt;. The README covers installation and usage of the command. If you come across a package whose types don't resolve correctly, issues are open: that's exactly the kind of edge case that makes the tool better.&lt;/p&gt;

</description>
      <category>assetmapper</category>
      <category>javascript</category>
      <category>symfony</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
