The following works in TypeScript 3.x:
class Foo {
a?: string;
b?: string;
c: number = 123;
}
Note that you need to initialise any members that are not optional (either inline as shown or in the constructor).
More Related Contents:
- What is “not assignable to parameter of type never” error in TypeScript?
- Expected 3 type arguments but got 1 but it should infer 2 types
- Import class in definition file (*d.ts)
- TypeScript union of string and string literals
- What does the `is` keyword do in typescript?
- 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?
- TypeScript: Accept all Object keys that map to a specific type
- Typescript interface default values
- How to configure custom global interfaces (.d.ts files) for TypeScript?
- How to selectively assign from one Partial to another in typescript
- Experimental decorators warning in TypeScript compilation
- Using latest JavaScript features in TypeScript, such as ES2018
- How to define an opaque type in TypeScript?
- What is the Record type?
- Mapping tuple-typed value to different tuple-typed value without casts
- TypeScript function return type based on input parameter
- What does “homomorphic mapped type” mean?
- What does “all legal JavaScript is legal TypeScript” mean?
- Declare a type that allows all parts of all levels of another type
- Empty interface allow any object?
- extend and only specify known properties?
- RxJs get value from observable
- Extending vs. implementing a pure abstract class in TypeScript
- Embed TypeScript code in an HTML document
- Extending global types (e.g. “Window”) inside a typescript module
- How to type pipe function using variadic tuple types in TypeScript 4?
- TypeScript keyof index type is too wide
- typescript generic type with equal operator means?
- Array containing all options of type value in Typescript
- Accept any object as argument in function