How to add custom “typings” in typescript 2.0 / 3.0

You can create local custom typings just for your project, where you can declare types for JS libraries. For that, you need to: Create directory structure to keep your type declaration files so that your directory structure looks similar to this: . ├── custom_typings │   └── some-js-lib │   └── index.d.ts └── tsconfig.json In the index.d.ts … Read more

How to prevent “Property ‘…’ does not exist on type ‘Global'” with jsdom and typescript?

Original Answer To Avoid Error Put this at the top of your typescript file const globalAny:any = global; Then use globalAny instead. globalAny.document = jsdom(”); globalAny.window = global.document.defaultView; Updated Answer To Maintain Type Safety If you want to keep your type safety, you can augment the existing NodeJS.Global type definition. You need to put your … Read more

What is the Record type?

Can someone give a simple definition of what Record is? A Record<K, T> is an object type whose property keys are K and whose property values are T. That is, keyof Record<K, T> is equivalent to K, and Record<K, T>[K] is (basically) equivalent to T. Is Record<K,T> merely a way of saying “all properties on … Read more

‘this’ implicitly has type ‘any’ because it does not have a type annotation

The error is indeed fixed by inserting this with a type annotation as the first callback parameter. My attempt to do that was botched by simultaneously changing the callback into an arrow-function: foo.on(‘error’, (this: Foo, err: any) => { // DON’T DO THIS It should’ve been this: foo.on(‘error’, function(this: Foo, err: any) { or this: … Read more

Typescript 2.0. “types” field in tsconfig.json

As of TypeScript 2.* the ‘tsconfig.json’ has the following two properties available: { ‘typeRoots’: [], ‘types’: [] } I’ll detail both in order. ‘typeRoots’ specifies root folders in which the transpiler should look for type definitions (eg: ‘node_modules’). If you’ve been using typescript, you know that for different libraries that have not been written using … Read more

How to configure custom global interfaces (.d.ts files) for TypeScript?

“Magically available interfaces” or global types is highly discouraged and should mostly be left to legacy. Also, you should not be using ambient declaration files (e.g. d.ts files) for code that you are writing. These are meant to stand-in the place of external non-typescript code (essentially filling in the typescript types into js code so … Read more

TypeScript Import Path Alias

So after reading your comment, I realized I misunderstood your question! If you want to control the paths from an imported package’s perspective, just use set the main property of your package.json to a file that properly represents the object graph of your module. { “main”: “common-utils/dist/es2015/index.js” } If you’re attempting to control the import … Read more