javascript - Importing Victor.js in TypeScript

Mots clés : javascripttypescriptimportmodulejavascript

meilleur 3 Réponses javascript - Importing Victor.js in TypeScript

vote vote

99

import Victor from "victor";  const foo = new Victor(1, 2); console.log(foo.y); 
{   "compilerOptions": {     "esModuleInterop": true   } } 
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) {     return (mod && mod.__esModule) ? mod : { "default": mod }; }; exports.__esModule = true; var victor_1 = __importDefault(require("victor")); var foo = new victor_1["default"](1, 2); console.log(foo.y); 
{   "compilerOptions": {     "esModuleInterop": true,     "module": "es6"   } } 
import Victor from "victor"; var foo = new Victor(1, 2); console.log(foo.y); 
$ node --experimental-modules test.mjs 
(node:18394) ExperimentalWarning: The ESM module loader is experimental. 2 
vote vote

89

module.exports = class AthenaExpress { ...more code.. } 
{   "compilerOptions": {     "outDir": "dist/",     "sourceMap": true,     "noImplicitAny": true,     "module": "commonjs",     "target": "es6",     "jsx": "react"   },   "baseUrl": "./src",   "include": [     "**/*"   ],   "exclude": [     "node_modules"   ] } 
declare module 'athena-express' {     import * as aws from "aws-sdk";     interface ConnectionConfigInterface {         aws: typeof aws,         s3: string,         getStats: boolean     }     interface QueryResultsInterface {         Items: any[],         DataScannedInMB: number,         QueryCostInUSD: number,         EngineExecutionTimeInMillis: number,         Count: number,     }      interface QueryInterface {         sql: string,         db: string,     }      type QueryResult = QueryResultsInterface      interface AthenaExpressInterface {         new: (config: ConnectionConfigInterface) => any,         query: (query: QueryInterface) => QueryResult,     }      class AthenaExpress {         new: (config: ConnectionConfigInterface) => any;         constructor(config: ConnectionConfigInterface);         query: (query: QueryInterface) => QueryResult;     } } 
import * as aws from "aws-sdk"; interface ConnectionConfigInterface {     aws: typeof aws,     s3: string,     getStats: boolean } interface QueryResultsInterface {     Items: any[],     DataScannedInMB: number,     QueryCostInUSD: number,     EngineExecutionTimeInMillis: number,     Count: number, }  interface QueryInterface {     sql: string,     db: string, }  type QueryResult = QueryResultsInterface  interface AthenaExpressInterface {     new: (config: ConnectionConfigInterface) => any,     query: (query: QueryInterface) => QueryResult, }  declare class AthenaExpress {     new: (config: ConnectionConfigInterface) => any;     constructor(config: ConnectionConfigInterface);     query: (query: QueryInterface) => QueryResult; }  export = AthenaExpress 
 tree src/backend/js     src/backend/js         ├── athena-express.d.ts         └── helloworld.ts 
vote vote

74

export{vector} 

Questions similaires