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
With nominal typing, a value has a type because you say it has a type, not because it has the same shape as that type.
Consider attaching brands to distinguish primitive and object types that are semantically distinct but structurally identical.
Be familiar with the various techniques for branding: properties on object types, string-based enums, private fields, and unique symbols.## Code Samples
interfaceVector2D{x: number;y: number;}functioncalculateNorm(p: Vector2D){returnMath.sqrt(p.x**2+p.y**2);}calculateNorm({x: 3,y: 4});// OK, result is 5constvec3D={x: 3,y: 4,z: 1};calculateNorm(vec3D);// OK! result is also 5
functionf(path: string){if(isAbsolutePath(path)){listAbsolutePath(path);}listAbsolutePath(path);// ~~~~ Argument of type 'string' is not assignable to// parameter of type 'AbsolutePath'}