I will not write all story here but people were using Teleprinter (Teletypewriter, Teletype, TTY) from 1830s and 1840s. As seen in the following pictures, it was an electromechanical device used for communicating text over telegraph lines etc. There wasn't any monitor, output was written in a paper. Some models were creating punched tape for data storage (either from typed input or from data received from a remote source) and read back such tape for local printing or transmission.
Nowadays, we use computers with monitor and operating system but Linux still uses TTY concept under the hood 🙂
You can find some diagrams below relation with Terminal Emulator and TTY
Teletypewriter(Teletype, Teleprinter or TTY)A restored 1930s Teletype is now a Linux TTYA Teletype Model 32 ASR used for Telex serviceVideo terminals like the DEC VT-100 (1978) made teletypes obsolete as computer I/O devicesTerminal Emulator (Pseudo type writer or PTY)Each Terminal Emulator window attached to separate TTY as shown in the above screenshot.Continue reading →
Below two code blocks are doing same job and the only difference is below second code block uses variadic tuple. Check the below links for more details.
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE";
const sendRequest = (url: string, method: HttpMethod) => {
switch (method) {
case 'DELETE':
break;
case 'GET':
break;
case 'POST':
break;
case 'PUT':
break;
default:
const exhaustiveCheck: never = method; // ✅ no error
throw new Error(`Unhandled case: ${exhaustiveCheck}`);
}
};
type Fruit = 'banana' | 'orange' | 'mango';
function exhaustiveCheck(param: never): never {
throw new Error('should not reach here')
}
function makeDessert(fruit: Fruit) {
switch (fruit) {
case 'banana': return 'Banana Shake'
case 'orange': return 'Orange Juice'
}
exhaustiveCheck(fruit) // 🚫 ERROR! `mango` is not assignable
}
Exhaustiveness checking is a good feature when you use switch block. Assume that you need to check a value of variable which data type is union type as shown below screenshot.
Shape is a discriminatedunion which consists of three types named Circle, Square and Triangle.
kind field is shared in Circle, Square and Triangle types so that if developer forgets to use any of kind field value in switch block, TypeScript will error in coding-time.