Skip to content

Instantly share code, notes, and snippets.

@phplaw
Last active June 4, 2019 19:01
Show Gist options
  • Save phplaw/3db28131894a255e424cfe898eea860d to your computer and use it in GitHub Desktop.
Save phplaw/3db28131894a255e424cfe898eea860d to your computer and use it in GitHub Desktop.
Learn TypeScript
let title: string = 'Hello World';
// or let title = $('#user_name').val();
(title as string).split(' ');
(<string>title).split(' ');
// fix window issue
// Element implicitly has an 'any' type because type 'Window' has no index signature?
declare global {
interface Window { MyNamespace: any; }
}
window.MyNamespace = window.MyNamespace || {};
// better than obove
interface Window: {
[key:string]: any; // Add index signature
}
// optional parameter syntax
function functionName(a: number, b?: number) {
}
// optional parameter check
function getSchool(name: string, address?: string, pinCode?: string): string {
if (address == undefined) {
console.log('address not defined');
}
if (pinCode == undefined) {
console.log('pincode not defined');
}
//...
}
#!/bin/bash
npm install @types/angular @types/jquery @types/node @types/socket.io @types/socket.io @types/socket.io-client @types/googlemaps @types/express
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment