but in typescript this.constructor.prop causes error “TS2339: Property ‘prop’ does not exist on type ‘Function'”.
Typescript does not infer the type of constructor
to be anything beyond Function
(after all … the constructor might be a sub class).
So use an assertion:
class SomeClass {
static prop = 123;
method() {
(this.constructor as typeof SomeClass).prop;
}
}
More on assertions
Related Contents:
- TypeScript “this” scoping issue when called in jquery callback
- Interfaces vs Types in TypeScript
- Typescript: deep keyof of a nested object
- typescript interface require one of two properties to exist
- Typescript derive union type from tuple/array values
- Exclude property from type
- How to write PickByValue type?
- How to implement a typescript decorator?
- How to get query params from url in Angular 2?
- Typescript Discriminated Union allows invalid state
- What is the Record type in typescript?
- How to pass optional parameters while omitting some other optional parameters?
- Types in object destructuring
- Typescript Distributive Conditional Types
- Chaining RxJS Observables from http data in Angular2 with TypeScript
- Typescript, merge object types?
- How can I declare a global variable in Angular 2 / Typescript? [closed]
- Types for function that applys name of function and arguments
- Angular2 canActivate() calling async function
- Typescript Interface – Possible to make “one or the other” properties required?
- Typescript: TS7006: Parameter ‘xxx’ implicitly has an ‘any’ type
- How to display json object using *ngFor
- Is there a way to “extract” the type of TypeScript interface property?
- Keyof inferring string | number when key is only a string
- Typescript Key-Value relation preserving Object.entries type
- How to avoid imports with very long relative paths in Angular 2?
- Typescript: Can I define an n-length tuple type?
- Object destructuring with property names that are not valid variable names
- How to reject in async/await syntax?
- Can’t import CSS/SCSS modules. TypeScript says “Cannot Find Module”
- What’s the meaning of “=>” in TypeScript? (Fat Arrow)
- Exclude/overwrite npm-provided typings
- How to use array.map with tuples in typescript?
- typescript: validate excess keys on value, returned from function
- Rules for the use of angle brackets in TypeScript
- Mapping tuple-typed value to different tuple-typed value without casts
- How can I declare a global variable in Angular 2 and up / Typescript? [closed]
- Enforce that an array is exhaustive over a union type
- How to watch and reload ts-node when TypeScript files change
- Why `downlevelIteration` is not on by default?
- Naming of TypeScript union and intersection types
- Typescript: Retrieve element type information from array type
- Property ‘includes’ does not exist on type ‘string[]’
- Obtaining the return type of a function
- Test for array of string type in TypeScript
- TypeScript and field initializers
- typescript generic type with equal operator means?
- Types from both keys and values of object in Typescript
- How to add custom “typings” in typescript 2.0 / 3.0
- Element implicitly has an ‘any’ type because type ‘Window’ has no index signature?