Created
August 9, 2020 11:54
-
-
Save jaycosaur/580bcd501ff20adc07a931e982020245 to your computer and use it in GitHub Desktop.
Interfaces [typescript] - Typescript to Python field guide
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 FileHandler { | |
open: () => string; | |
close: () => void; | |
} | |
// with usage like | |
function getContents(fileHandler: FileHandler): string { | |
try { | |
return fileHandler.open(); | |
} finally { | |
fileHandler.close(); | |
} | |
} | |
const myFile = { | |
open: () => "hello", | |
close: () => null, | |
}; | |
const contents = getContents(myFile); // "hello" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment