TypeScript npm typings feature changes import semantics -


when importing typings (.d.ts) file using import x = require('...') pattern semantics change when package.json typings entry used.

for example, following declaration file imports when no package.json typings entry used generates error ts2656 (exported external package typings file not module) when used typings entry:

declare module 'mymodule' {   export function myfunc(source: string): string; } 

whereas same file minus declare module {} imports when used package.json typings entry generates error ts2307 (cannot find module) when used without typings entry.

export function myfunc(source: string): string; 

why change in semantics?

it looks if use new npm typings feature have maintain both npm , non-npm versions of typings files.

i hit while trying use projects typings file within project (typescript not in current project's package.json typings entries, seems confine it's search to./node_modules).

tested typescript 1.7.5.

per the documentation, typings key in package.json analogue main key points single node.js module. such, d.ts file pointed typings also expected single exported module declaration, not d.ts bundle.

the specific rationale given documentation is:

the rationale typings should not bring new compatible sources set of compiled files; otherwise source files (i.e. .ts files) considered compiler part of user code , compiled, , outputs in package can overwritten resulting .js outputs.

additionally, loading typings should not pollute global scope bringing potentially conflicting entries different version of same library. modules have own scope, , not pollute global namespace, if typings file not module, polluting user global scope, , cause conflicts other packages depend on package. /// <references ... /> can bring global declarations global scope , should avoided.

(personally, you, think implementation totally wrong , silly. typings key should have pointed single file containing multiple relative declare module './foo' { … } declarations describing entire package, means of avoiding pollution of filesystem tons of typescript-specific files. unfortunately, ship has sailed @ point, package has have ton of typescript-specific d.ts files side-by-side javascript modules, plus redundant description of main module’s typing.)


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -