typescript1.6

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 = //...

Anonymous/inline interface implementation in TypeScript

隐身守侯 提交于 2019-12-20 11:48:11
问题 I've just started with TypeScript and I'm trying to understand why the following inline object definition isn't considered valid. I have a collection of objects - their type is irrelevant (to me), but they implement the interface so that when I iterate through them I know that the interface methods will be present in each object in the collection. I came across a "compiler" error when I tried to create an object with private information required to implement the required method: interface

Browser error messages referencing correct typescript file using outFile

限于喜欢 提交于 2019-12-13 00:59:35
问题 I am using the outFile option in the tsconfig.json to compile my typescript files into one .js file. I am generating a source map. Error messages are not referenced to the typescript file though. Examples: script.ts: throw 'Error' tsconfig.json: { "compilerOptions": { "sourceMap": true } } Compiling (tsc 1.6.2) will generate: script.js: throw 'Error script.js.map: {"version":3,"file":"script.js","sourceRoot":"","sources":["script.ts"],"names":[],"mappings":"AACA,MAAM,QAAQ,CAAC"} The browser's

user defined type guards [typescript]

戏子无情 提交于 2019-12-11 04:30:25
问题 With TypeScript 1.6 is it possible to write functions to check objects against interfaces. (Below is the anncouncement from MSDN and how to use it.) My question targets the return expression return a.name === 'kitty'; : Plays it an role? Must all cats called kitty? User defined type guards [http://blogs.msdn.com/b/typescript/archive/2015/09/16/announcing-typescript-1-6.aspx] In earlier versions of TypeScript, you could use if statements to narrow the type. For example, you could use: if

What is the scope of a type alias?

筅森魡賤 提交于 2019-12-11 03:04:44
问题 What is the scope of a typescript type alias? I have this alias and I think that I might want to declare it globally somehow: type ResouceResult<T> = T & { $promise: ng.IPromise<T>, $resolved: boolean }; 回答1: Section 3.9 of Typescript 1.5 language specification: http://www.typescriptlang.org/Content/TypeScript%20Language%20Specification.pdf 3.9 Type Aliases A type alias declaration introduces a type alias in the containing module so module 回答2: declare it globally If your file is a global,

Should I use ES6 import or reference path when loading Typescript definition file?

本小妞迷上赌 提交于 2019-12-10 15:27:24
问题 Would it be preferred to use ES6 import or reference path comment when loading Typescript (1.6 above) definition files? import {describe, it, expect, jasmine} from './jasmine' or import * as jasmine from './jasmine' vs. ///<reference path="jasmine.d.ts"/> 回答1: @Yudhistira Arya, as you can see from @ahejlsberg ES6 Modules #2242 post It is recommended that TypeScript libraries and applications be updated to use the new syntax, but this is not a requirement. The new ES6 module syntax coexists

What does “use strict” add for TypeScript code?

家住魔仙堡 提交于 2019-12-10 13:56:30
问题 This question is a copy of “Use Strict” needed in a TypeScript file? There are some answers, but it is not clear for what does "use strict" statement in TypeScript, when tsc shoes me strict mode errors without this statement. But decided to ask as separated question aw well. I am using TypeScript 1.6 and for me it is not clear what does "use strict" statement add in TypeScript? Using "use strict"; statement looks like double check. Since tsc shows strict mode errors without this statement.

Access to static properties via this.constructor in typescript

℡╲_俬逩灬. 提交于 2019-12-09 14:10:23
问题 I want to write es6 class: class SomeClass { static prop = 123 method() { } } How to get access to static prop from method() without use SomeClass explicitly? In es6 it can be done with this.constructor , but in typescript this.constructor.prop causes error " TS2339: Property 'prop' does not exist on type 'Function' ". 回答1: but in typescript this.constructor.prop causes error "TS2339: Property 'prop' does not exist on type 'Function'". Typescript does not infer the type of constructor to be

tsconfig.json not used by TypeScript compiler?

人盡茶涼 提交于 2019-12-07 21:00:36
问题 I'm new to TypeScript. I am trying to setup the use of it in WebStorm. I have created a tsconfig.json file in the root of my project and changed the builtin ts compiler to version 1.6.2. Still I need to include reference paths in every ts file. I hoped this would not be needed anymore once I defined the tsconfig.json file. I tried to isolate the issue and went testing outside WebStorm. The issue remains. This is my setup: I installed TypeScript with "npm install -g typescript". I created a