Webassets + Typescript, cannot resolve symbols/modules
<p>I have a flask project with the following structure:</p>

<pre><code>ââ app.py
ââ project
|  ââ __init__.py
|  ââ static
|     ââ typescript
|        ââ app.ts
ââ typings
   ââ globals
   |  ââ ... # multiple imported ts libraries
   ââ index.d.ts
</code></pre>

<p>I'm using a webpacker integration called <a href="https://flask-assets.readthedocs.io/en/latest/" rel="nofollow">Flask Assets</a>. I've set up the compilation like so (in <code>__init__.py</code>)</p>

<pre><code>ts = get_filter('typescript')
ts.load_paths = [
    #os.path.join(config.APP_ROOT, '..', 'typings'), # doesn't do anything :/
    os.path.join(app.static_folder, 'typescript')
]

assets.register('javascript', Bundle(
    'typescript/app.ts', 
    filters = (ts, 'jsmin'),
    output = 'js/app-%(version)s.js'
))
</code></pre>

<p>My app.ts is, more or less, </p>

<pre><code>class SomeClass {
    ... various class methods, using things like jQuery and CryptoJS
}
</code></pre>

<p>no imports - I'm not really sure whether or not I need them.</p>

<p>The specific error I'm getting is </p>

<pre><code>Cannot find name 'JQuery'.
../../../../../var/folders/5t/4x0gmsdx0dbbgv_fr3cv3x6m0000gn/T/tmphFTSQo.ts(7,17): error TS2503: Cannot find namespace 'CryptoJS'.
../../../../../var/folders/5t/4x0gmsdx0dbbgv_fr3cv3x6m0000gn/T/tmphFTSQo.ts(10,27): error TS2304: Cannot find name '$'.
... a bunch more about other symbols
</code></pre>

<p>I <em>kind of</em> solved it...</p>

<pre><code>glob_string = os.path.join(config.APP_ROOT, '..', 'typings', '*', '*', '*.d.ts')

assets.register('javascript', Bundle(
    glob.glob(glob_string),
    'typescript/app.ts',
    filters = ('typescript', 'jsmin'),
    output = 'js/app-%(version)s.js'
))
</code></pre>

<p>basically I just "manually" add all the definition files to the bundle (using glob). It's not sufficient to just add the <code>index.d.ts</code> in the root of the typings dir as the typescript filter copies the <code>.ts</code> to a temp file (in <code>/tmp</code>) before compiling and the paths in <code>index.d.ts</code> are relative.</p>

<p>it should also be noted that <code>ts.load_paths</code> does nothing...</p>

python typescript flask webpack webassets