CopyPastor

Detecting plagiarism made easy.

Score: 0.8181576728820801; Reported for: String similarity Open both answers

Possible Plagiarism

Reposted on 2019-05-27
by Lu4

Original Post

Original - Posted on 2019-05-23
by Lu4



            
Present in both answers; Present only in the new answer; Present only in the old answer;

There is another way to create nominal types, which seems little more laconic. As discussed in https://stackoverflow.com/questions/56199492/atomic-type-discrimination-nominal-atomic-types-in-typescript
The basic example is as follows:
export type Kilos<T> = T & { readonly discriminator: unique symbol }; export type Pounds<T> = T & { readonly discriminator: unique symbol };
export interface MetricWeight { value: Kilos<number> } export interface ImperialWeight { value: Pounds<number> } const wm: MetricWeight = { value: 0 as Kilos<number> } const wi: ImperialWeight = { value: 0 as Pounds<number> } wm.value = wi.value; // Gives compiler error wi.value = wi.value * 2; // Gives compiler error wm.value = wi.value * 2; // Gives compiler error const we: MetricWeight = { value: 0 } // Gives compiler error
Please consider the following question:
https://stackoverflow.com/questions/56199492/atomic-type-discrimination-nominal-atomic-types-in-typescript?noredirect=1#comment99047026_56199492
With it's example:
export type Kilos<T> = T & { readonly discriminator: unique symbol }; export type Pounds<T> = T & { readonly discriminator: unique symbol };
export interface MetricWeight { value: Kilos<number> } export interface ImperialWeight { value: Pounds<number> } const wm: MetricWeight = { value: 0 as Kilos<number> } const wi: ImperialWeight = { value: 0 as Pounds<number> } wm.value = wi.value; // Gives compiler error wi.value = wi.value * 2; // Gives compiler error wm.value = wi.value * 2; // Gives compiler error const we: MetricWeight = { value: 0 } // Gives compiler error

        
Present in both answers; Present only in the new answer; Present only in the old answer;