Skip to content

Instantly share code, notes, and snippets.

@jaycosaur
Created August 9, 2020 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaycosaur/580bcd501ff20adc07a931e982020245 to your computer and use it in GitHub Desktop.
Save jaycosaur/580bcd501ff20adc07a931e982020245 to your computer and use it in GitHub Desktop.
Interfaces [typescript] - Typescript to Python field guide
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