Quantcast
Channel: User Ryan Cavanaugh - Stack Overflow
Browsing all 38 articles
Browse latest View live

Comment by Ryan Cavanaugh on Type 'undefined' is not assignable to type 'xxx'...

How is x declared?

View Article



Comment by Ryan Cavanaugh on How do I make TypeScript treat my file as a module?

YMMV but in my experience, if you're writing actual code, it's extremely difficult to get more than 20 lines into a file without writing an import. Just logistically, you can't really have more than a...

View Article

Comment by Ryan Cavanaugh on How to define type for a function callback (as...

@SgtPooki post your own answer. That's how the site works.

View Article

Comment by Ryan Cavanaugh on Why am I getting an error "Object literal may...

A "typo" can also manifest if, for example, you change an API somewhere and intentionally break downstream code.

View Article

Comment by Ryan Cavanaugh on Typescript, JSON.parse error: "Type 'null' is...

No, because the very first step of JSON.parse is an implicit coercion of its argument to a string. JSON.parse(32)"succeeds" for the same reason but is not allowed either.

View Article


Comment by Ryan Cavanaugh on How to make Flow and Typescript work together in...

Why not just add the commas for now? TS will accept them.

View Article

Comment by Ryan Cavanaugh on How to Instantiate new HTMLElement?

TypeScript doesn't change the meaning of existing code.

View Article

Comment by Ryan Cavanaugh on Why doesn't Object.keys return a keyof type in...

satisfies doesn't do anything to prevent aliasing with a supertype alias, which is the problem. You would need exact types to solve this "problem"

View Article


Comment by Ryan Cavanaugh on Is there destructor in TypeScript?

Bad comment. JavaScript isn't Angular.

View Article


Comment by Ryan Cavanaugh on How to suppress "error TS2533: Object is...

Sounds like a lint rule

View Article

Comment by Ryan Cavanaugh on Naming of TypeScript union and intersection types

This is the terminology CS type theorists have been since the 70's

View Article

Comment by Ryan Cavanaugh on Typescript: why function without parameters can...

There isn't, and there also isn't a good reason to enforce this. A program with an additional unused parameter isn't plausibly more correct than one without it.

View Article

Answer by Ryan Cavanaugh for How to differentiate between a .ts file and a .d.ts

This isn't possible. TypeScript's module resolution algorithm will always prefer the .ts file over a .d.ts file of the same name, since it assumes the latter is a build output of the former. You should...

View Article


How do I use namespaces with TypeScript external modules?

I have some code:baseTypes.tsexport namespace Living.Things { export class Animal { move() { /* ... */ } } export class Plant { photosynthesize() { /* ... */ } }}dog.tsimport b =...

View Article

Answer by Ryan Cavanaugh for How to relate a version of @types package to the...

The major and minor versions of the DefinitelyTyped packages are supposed to correspond to the major and minor versions of the package they are types for. The patch version increments whenever the...

View Article


Answer by Ryan Cavanaugh for Why can't TypeScript modules implement or adhere...

You can force a compile error if a module doesn't adhere to an interface like this (technically non-zero runtime overhead, but unlikely to actually matter):interface foo { bar(): number;}module mod {...

View Article

Answer by Ryan Cavanaugh for TypeScript Coding Style Guide?

The TypeScript team doesn't issue an "official" style guide for other projects using TypeScript. The guidelines for working on the compiler itself are both too specific and not broad enough for general...

View Article


Answer by Ryan Cavanaugh for Strange behaviour of callback function in...

TypeScript doesn't know that filter's callback runs immediately, so if for example filter's callback ran later (let's say on a setTimeout), your code would crash under a call like this:const a: Args =...

View Article

Answer by Ryan Cavanaugh for Can I define a Typescript interface with...

You need to use as const to make a nonwidening string literal type at the key declarations:const KEY_SAUCE = `${NAMESPACE}/sauce` as const;const KEY_CRUST = `${NAMESPACE}/crust` as const;

View Article

Answer by Ryan Cavanaugh for In typescript, why is `[boolean, string?]`...

These types are different:// OKconst p1: [boolean, string?] = [true, undefined];// Errorconst p2: [boolean, string] | [boolean] = [true, undefined];

View Article
Browsing all 38 articles
Browse latest View live




Latest Images