You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should probably mention in the session that the moment you create a private member in a class, you effectively achieve Nominal typing in TypeScript!
classNamed{
#name: string;constructor(name: string){this.#name =name;}getname(){returnthis.#name }}classPerson{
#name: string;// this is sufficient to create incompatible classesjob: string;constructor(name: string,job: string){this.#name =name;this.job=job;}getname(){returnthis.#name }}constcpScott=newPerson('CP Scott','Journalist',);consthello=(named: Named): string=>`Hello ${named.name}`;consthelloCPScott=hello(cpScott);// Argument of type 'Person' is not assignable to parameter of type 'Named'.// Property '#name' in type 'Person' refers to a different member that cannot be accessed from within type 'Named'.(2345)
Suggested here:
#40 (review)
The text was updated successfully, but these errors were encountered: