This file contains 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
const order = { | |
what: 'Macbook Air' as Product, // or "as 'MacbookAir'" | |
how: 'bitcoin' | |
}; | |
purchase(order.what); // ok |
This file contains 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
const order = { | |
what: 'Macbook Air', | |
how: 'bitcoin' | |
}; | |
order.what = 'Lenovo'; // valid |
This file contains 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
let newToy: Product = 'Macbook Air'; | |
purchase(newToy); // ok |
This file contains 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
purchase('Macbook Air'); | |
const newToy = 'Macbook Air'; | |
purchase(newToy); // ok |
This file contains 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 Product = 'iPad' | 'Mac Mini' | 'Macbook Air' | 'Macbook Pro'; | |
export function purchase(what: Product) { | |
// mine bitcoin… | |
// send to apple… | |
} |
This file contains 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
const loc: [number, number] = [10, 20]; | |
panTo(loc); |
This file contains 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
const loc: any = [10, 20]; | |
panTo(loc); | |
const loc = [10, 20]; | |
panTo(loc as any); |
This file contains 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
const loc = [10, 20]; | |
loc.push(30); |
This file contains 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
// Parameter is a (latitude, longitude) pair. | |
function panTo(where: [number, number]) { /* ... */ } | |
// Inline: | |
panTo([10, 20]); // inline: ok | |
// Reference: | |
const loc = [10, 20]; | |
panTo(loc); // reference. Will this work? |
This file contains 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
export function purchase(what: string) { /* ... */ } | |
purchase('Macbook Air'); // Inline | |
const product = 'Macbook Air'; | |
purchase(product); // reference |