node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ‘;’ expected error after installation of Angular 6

This problem might arise due to version mismatch. To solve your problem you need to do following changes in your package.json file. Step 1 : Go to package.json and modify “rxjs”: “^6.0.0” to “rxjs”: “6.0.0” Step 2 Run npm install in your project. There is no need to change the typescript version. (Mine: “typescript”: “~2.7.2”) Edit: If you are using rxjs-compat then you also need to do following in order … Read more

Understanding esModuleInterop in tsconfig file

Problem statement Problem occurs when we want to import CommonJS module into ES6 module codebase. Before these flags we had to import CommonJS modules with star (* as something) import: We can see that * was somehow equivalent to exports variable. It worked fine, but it wasn’t compliant with es6 modules spec. In spec, the namespace record in star … Read more

Angular File Upload

Here is a working example for file upload to api: Step 1: HTML Template (file-upload.component.html) Define simple input tag of type file. Add a function to (change)-event for handling choosing files. Step 2: Upload Handling in TypeScript (file-upload.component.ts) Define a default variable for selected file. Create function which you use in (change)-event of your file input tag: If … Read more

Interfaces vs Types in TypeScript

Original Answer (2016) As per the (now archived) TypeScript Language Specification: Unlike an interface declaration, which always introduces a named object type, a type alias declaration can introduce a name for any kind of type, including primitive, union, and intersection types. The specification goes on to mention: Interface types have many similarities to type aliases for object type literals, … Read more

Could not find a declaration file for module ‘module-name’. ‘/path/to/module-name.js’ implicitly has an ‘any’ type

That feeling when you are looking out for two days and find it like this: just remove .js from “main”: “dist/index.js” in package.json and everything works fine! UPD: this answer relative if you have your own npm package, if not – see my answer below. And if above answer not resolved import your module, try just add typings in package.json: Of course, here folder dist – it’s … Read more

How to convert a string to number in TypeScript?

Exactly like in JavaScript, you can use the parseInt or parseFloat functions, or simply use the unary + operator: All of the mentioned techniques will have correct typing and will correctly parse simple decimal integer strings like “123”, but will behave differently for various other, possibly expected, cases (like “123.45”) and corner cases (like null).  Table taken from this answer

How can I define an array of objects?

You are better off using a native array instead of an object literal with number-like properties, so that numbering (as well as numerous other array functions) are taken care of off-the-shelf. What you are looking for here is an inline interface definition for your array that defines every element in that array, whether initially present or introduced later: If … Read more