How do I set a peer dependency optional?

Since NPM v7.x, you can use the peerDependenciesMeta package.json config, which allows exactly that option. For example, in your “Module A” package.json: “peerDependencies”: { “winston”: “> 1.0.0 <= 1.2.10”, “foo”: “~2.3.0” }, “peerDependenciesMeta”: { “winston”: { “optional”: true } } In this case, when installing Module A as a dependency of another project, it will … Read more

How to configure VSCode to run Yarn 2 (with PnP) powered TypeScript

I had this problem last night while migrating to Yarn v2 and using PnP. Make sure that after running yarn dlx @yarnpkg/sdks vscode the following folder structure was created inside your .yarn directory: .yarn/sdks/typescript/lib. Change your VSCode workspace configuration to add the following: “typescript.tsdk”: “.yarn/sdks/typescript/lib” I also had another problem with step 1 while using … Read more

Typescript string type that must start with specific characters

As of TypeScript 4.1, you can use a template literal type for this. type StartsWithPrefix = `prefix${string}`; This works for type unions as well: // `abc${string}` | `def${string}` type UnionExample = `${‘abc’ | ‘def’}${string}`; // For your example: type MyPrefixTypes = `${MyStringTypes}${string}`; const ok: UnionExample=”abc123″; const alsoOk: UnionExample=”def123″; const notOk: UnionExample=”abdxyz”; // Note that a … Read more

Destructured parameter properties in constructor

What about: class Destructed { private prefix: string; private suffix: string; constructor(opts: DestructedOptions) { Object.assign(this, opts); } } Also, there’s an open issue on this: Combining destructuring with parameter properties Edit If you want to avoid re-writing the properties in the class then you’ll need to make the members public, when that’s the case then … Read more

ts-node and mocha ‘TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts”‘ error even with “ts-node/esm” loader and CommonJS modules

i’m using same configuration like yours but it only work when i downgrade to ts-node@9, and then i tried this option in my .mocharc.json and now it’s working as i expected { “extensions”: [“ts”], “spec”: [“**/*.spec.*”], “node-option”: [ “experimental-specifier-resolution=node”, “loader=ts-node/esm” ] }

In TypeScript, why is an empty array inferred as “any[]” when noImplicitAny is true, and inferred as “never[]” when it is false?

This issue was raised in microsoft/TypeScript#36987. The authoritative (but not particularly informative) answer there is that this behavior is as intended, and required for backward compatibility. Generally speaking TypeScript doesn’t introduce breaking changes unless these changes improve many more things than they break. When the –noImplicitAny compiler option and the –strictNullChecks compiler option are both … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)