Linq javascript library with typescript es6 import syntax

I use linq (npm linq) with specific linq.d.ts files, however I cannot get it to work with ES 6 syntax.

I tried the usual one import {Enumerable} from "linq", but he refused to find "linq". I changed the handle to have declare module "linq", whereas normally it would not have quotes. Linq now solves, but I have to use EnumerableStatic, but Enumerablenot is required for the output code EnumerableStatic. I thought I could get around this by doing it import {EnumerableStatic as Enumerable} from "linq", however this cannot be resolved correctly.

Has anyone worked, and how to import it?

+4
source share
4 answers

The definition file must be updated:

  • , 3.0.5. Enumerable.From Enumerable.From. .
  • . :

    declare module "linq" {
        export = Enumerable;
    }
    
  • , module.exports = Enumerable JavaScript, :

    import * as Enumerable from "linq";
    
+2

main.ts:

/// <reference path="typings/linq/linq.d.ts" />

import { Enumerable } from 'linq';

TS2307: Cannot find module 'linq'. . tsc.js, , loadModuleFromNodeModules failedLookups:

[ '/var/www/TypeScript-Playground/node_modules/linq.ts',
  '/var/www/TypeScript-Playground/node_modules/linq.tsx',
  '/var/www/TypeScript-Playground/node_modules/linq.d.ts',
  '/var/www/TypeScript-Playground/node_modules/linq/index.ts',
  '/var/www/TypeScript-Playground/node_modules/linq/index.tsx',
  '/var/www/TypeScript-Playground/node_modules/linq/index.d.ts',
  '/var/www/node_modules/linq.ts',
  '/var/www/node_modules/linq.tsx',
  '/var/www/node_modules/linq.d.ts',
  '/var/www/node_modules/linq/package.json',
  '/var/www/node_modules/linq/index.ts',
  '/var/www/node_modules/linq/index.tsx',
  '/var/www/node_modules/linq/index.d.ts',
  '/var/node_modules/linq.ts',
  '/var/node_modules/linq.tsx',
  '/var/node_modules/linq.d.ts',
  '/var/node_modules/linq/package.json',
  '/var/node_modules/linq/index.ts',
  '/var/node_modules/linq/index.tsx',
  '/var/node_modules/linq/index.d.ts',
  '/node_modules/linq.ts',
  '/node_modules/linq.tsx',
  '/node_modules/linq.d.ts',
  '/node_modules/linq/package.json',
  '/node_modules/linq/index.ts',
  '/node_modules/linq/index.tsx',
  '/node_modules/linq/index.d.ts' ]

, /var/www/TypeScript-Playground/node_modules/linq/linq.js .

Gitter issues. , https://github.com/Microsoft/TypeScript/issues/2242 , :

TypeScript 1.5 , :

, .

ES6 .

TypeScript - export = Point.

TypeScript import-equals import Math = require ( "math" ).

, linq .

+2

linq-ts, Typescript

linq-es2015. . : https://github.com/ENikS/LINQ/tree/examples/TypeScript

+1

retyped-linq-tsd-ambient, npm. ATW, linq.3.0.3-Beta4.d.ts - .

:

/// <reference path="../../node_modules/retyped-linq-tsd-ambient/linq.3.0.3-Beta4.d.ts" />

... linq.js. , :

declare module "linq" {
     export = Enumerable;
}

linq typescript intellisence.

: # "" . typescript, #.

Note. There is also a promising linq-ts library written by typescript from scratch. It seems to print a lot stronger. Unfortunately, I could not get it to compile / work in my project due to some es6 (-shim) dependencies.

0
source

Source: https://habr.com/ru/post/1613218/


All Articles