typescript1.7

Typescript: “Cannot find module” with valid typings

你离开我真会死。 提交于 2021-02-08 12:16:30
问题 I just started a new nodejs project using typescript. I installed Typings (https://github.com/typings/typings) and used that to install reference files for node v4.x and express v4.x. My node version is v4.2.6 My typescript version is v1.7.5 My project directory is laid out thus: package.json tsconfig.json typings.json src/ app.ts typings/ main.d.ts main/ambient/node/node.d.ts main/ambient/express/express.d.ts The contents of typings/main.d.ts are as follows: /// <reference path="main/ambient

Correct way of getting type for a variable declaration in a typescript AST?

非 Y 不嫁゛ 提交于 2021-02-07 19:46:07
问题 Took a look at the declarationEmitter and for variable declarations, it has the function #emitVariableDeclaration which eventually calls #writeTypeOfDeclaration . This code does what is says---it takes a variable declaration and prints the variable and its type---this is exactly what I want to do. The problem is that when I replicate this code, the VariableDeclaration node has no symbol property...and thus, the type is always "any". Is there a missing step to initialize "symbols"? //sample

How do you get inferred type from a typescript AST?

杀马特。学长 韩版系。学妹 提交于 2020-12-29 13:20:08
问题 I'm using the built-in parser to generate the AST from source code: const ts = require('typescript') //... const ast = ts.createSourceFile(filename, fs.readFileSync(filename).toString(), ts.ScriptTarget.ES6, true) Is there a way to get the inferred type of a variable from the AST? For example, in the code below, bar is of type IBar . The compiler knows about that type--- bar.foo() doesn't compile---how can I programmatically get the type? interface IBar { bar() } const foo : IBar = //...

custom property with google marker in type script

本小妞迷上赌 提交于 2020-02-21 03:15:44
问题 I'm using type script and getting below error when trying to set custom property with Google marker. Can anyone please advice how to set custom property with Google Map Marker? Argument of type '{ position: LatLng; map: any; icon: string; zIndex: number; se10: any; }' is not assignable to parameter of type 'MarkerOptions'. Object literal may only specify known properties, and 'se10' does not exist in type 'MarkerOptions'. The following Javascript code is working well. var marker = new google

How can I setup my VS 2013 TypeScript project to compile my typescript files but exclude my node_modules?

蓝咒 提交于 2020-01-12 07:31:10
问题 I'm working on an angular2@beta project in VS 2013 after familiarizing myself with it in IntelliJ. IntelliJ can be set to find the tsconfig.json file and, as of TypeScript 1.6, it can therefore read the "exclude" property and not attempt to compile any of the node_modules. Now that I've moved to VS 2013 with TypeScript 1.7, I'm running into the issue where it's trying to compile the node_modules. I've included the tsconfig.json, but from what I've read, tsconfig.json is fully supported only

Angular2, RouteParams not working

旧城冷巷雨未停 提交于 2019-12-24 06:38:27
问题 I'm getting a error that is currently causing lots of frustration. Here's what I running with: ASP.NET Core 1.0 RC1 Angular2, 2.0.0-beta.15 TypeScript, 1.7.6.0 The error(s): Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode. Attempting redirect to: /Design/0DEAC46A-7F58-49F9-B67E-2C187DFA49A7/ Navigated to http://localhost:5000/ EXCEPTION: Cannot resolve all parameters for 'RouteParams'(?). Make sure that all the parameters are decorated with

How to import CommonJS module that uses module.exports= in Typescript

一世执手 提交于 2019-12-23 07:28:16
问题 The following produces valid, working ES5 but emits the error below. I'm using Typescript 1.7.5 and I think I've read the whole language spec and I cannot figure out why this error is produced. error TS2349: Cannot invoke an expression whose type lacks a call signature. a.js (ES5 ambient module with default export) function myfunc() { return "hello"; } module.exports = myfunc; a.d.ts declare module "test" { export default function (): string; } b.ts import test = require("test"); const app =

Overwrite function in TypeScript

允我心安 提交于 2019-12-13 07:27:14
问题 TypeScript: view on playground alert = (function (origAlert) { return function (...messages: any[]) { origAlert(messages.join(" ")) } })(alert) // Example alert(1, 2) I want to overwrite / redefine the function alert(message?: any) wich has already been declared in lib.d.ts before: declare function alert(message?: any): void; But alert = function... throws " Invalid left-hand side of assignment expression. " The point is that, function alert(...messages: any[]) { /* ... */ } would work * does

Typescript errors when referencing files with similar module names

倾然丶 夕夏残阳落幕 提交于 2019-12-13 07:26:16
问题 I have one typescript class like this; module my.services { export class MyService { ... } } And another like this; module com.my.component { import MyService = my.services.MyService; export class MyComponent { ... } } But in the 2nd class I get a Typescript error saying Module 'com.my' has no exported member 'services' What is the correct way to reference MyService in this case? 回答1: If we will take a look at what specification says about namespaces like 'A.B.C' here: namespace declarations

Differences in Typescript array literal syntax

本小妞迷上赌 提交于 2019-12-12 12:07:18
问题 Typescript allows one to define an Array with either syntax: var myStrArry1: string[] = []; or var myStrArry1: Array<string> = []; The compiled output appears to be the same. Does the compiler treat them identically, or are there some quirks to be aware of? 回答1: Does the compiler treat them identically, or are there some quirks to be aware of? They are identical. I prefer syntax 1 回答2: From the typescript documentation, they are treated identically, one is simply a shorthand notation for the