This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Dog { | |
(food: string): void; | |
type: string; | |
} | |
const dogFactory = (breed: string): Dog => { | |
const eat = (food: string) => console.log(`Eating ${food}.`); | |
eat.type = breed; | |
return eat; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Protocol | |
class Dog(Protocol): | |
type: str | |
def __call__(self, food: str) -> None: | |
pass | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import NewType | |
Celsius = NewType("Celsius", float) | |
Fahrenheit = NewType("Fahrenheit", float) | |
def convert_to_fahrenheit(value: Celsius) -> Farenheit: | |
return Farenheit((value * 9 / 5) + 32) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Celsius = number; | |
type Fahrenheit = number; | |
function convertToCelsius(value: Fahrenheit): Celsius { | |
return (value * 9) / 5 + 32; | |
} | |
function convertToFahrenheit(value: Celsius): Fahrenheit { | |
return ((value - 32) * 5) / 9; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Celsius = { | |
type: "celsius"; | |
value: number; | |
}; | |
const celsius = (value: number): Celsius => ({ | |
value, | |
type: "celsius", | |
}); |
OlderNewer