Why can I avoid excess property check in typescript just by passing a reference to an object to a function rather than the object in its literal form?

It’s by design. In short, Typescript creators made it this way because they know Javascript is a very dynamic language with many such use cases. You should read this carefully: https://www.typescriptlang.org/docs/handbook/interfaces.html#excess-property-checks (however I bet the question arised from reading it). Object literals get special treatment Their logic might be like this: if you have a … Read more

Forcing excess-property checking on variable passed to TypeScript function

Hope this helps, this will cause it to fail. The underlying cause here is Typescripts reliance on structural typing which is alot better than the alternative which is Nominal typing but still has its problems. type StrictPropertyCheck<T, TExpected, TError> = Exclude<keyof T, keyof TExpected> extends never ? {} : TError; interface Animal { speciesName: string … Read more

ESLint – Configuring “no-unused-vars” for TypeScript

It’s a bit buried in the documentation, but if you add some things to the ‘extends’ property, you can use both the rules recommended by ESLint like no-unused-vars, and have it actually work in Typescript. Like so: “extends”: [ “eslint:recommended”, “plugin:@typescript-eslint/eslint-recommended”, “plugin:@typescript-eslint/recommended” ], @typescript-eslint/recommended seems to be the thing that allows eslint:recommended to deal with … 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