Guest User

Untitled

a guest
May 5th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. //commonjs-export-function.js
  2. module.exports = function() {
  3. return 'func';
  4. };
  5.  
  6. //commonjs-export-function.d.ts
  7. declare function func(): string;
  8. export = func;
  9.  
  10. //main.ts
  11. import { func } from './commonjs-function';
  12.  
  13. console.log(func());
  14.  
  15. tsc main.ts && node main.js
  16. main.ts(1,22): error TS2497: Module '"/Users/aleksandar/projects/typescript-playground/commonjs-function"' resolves to a non-module entity and cannot be imported using this construct.
  17.  
  18. *~ Note that ES6 modules cannot directly export callable functions.
  19. *~ This file should be imported using the CommonJS-style:
  20. *~ import x = require('someLibrary');
  21. ...
  22. export = MyFunction;
  23. declare function MyFunction(): string;
  24.  
  25. //commonjs-export-function.d.ts
  26. declare function func(): string;
  27. export = func;
  28.  
  29. //main.ts
  30. import func = require('./commonjs-export-function');
  31.  
  32. declare module 'promise-map-limit' {
  33.  
  34. type IIteratee<T, R> = (value: T) => Promise<R> | R;
  35.  
  36. function mapLimit<T, R>(
  37. iterable: Iterable<T>,
  38. concurrency: number,
  39. iteratee: IIteratee<T, R>
  40. ): Promise<R[]>;
  41.  
  42. export = mapLimit;
  43.  
  44. }
Add Comment
Please, Sign In to add comment