jcroll
jcroll

Reputation: 7165

Is there anyway in Typescript to get the type of an undefined class property?

Consider you have defined a class with a property like below but not yet set that property. Is there anyway to detect what type that property should be?

class User {

  username: string;
}

let user = new User();
console.log(typeof user.username) // string ???

Upvotes: 0

Views: 34

Answers (1)

Ryan Cavanaugh
Ryan Cavanaugh

Reputation: 220994

No. Types are erased. You can see this yourself by looking at the emitted JavaScript file; it is identical whether you wrote username: string or username: number.

Upvotes: 3

Related Questions