Skip to content

Instantly share code, notes, and snippets.

Ibrahim Šuta Ibro

Block or report user

Report or block Ibro

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Ibro
Ibro / package.json
Created Feb 20, 2016
Package json with webpack start script
View package.json
{
"name": "webpack-sample",
"version": "0.0.1",
"description": "Webpack sample - first try",
"main": "",
"scripts": {
"start": "webpack"
},
"repository": {
"type": "git",
@Ibro
Ibro / webpack.config.js
Created Feb 20, 2016
Webpack config with dev server
View webpack.config.js
module.exports = {
entry: __dirname + "/app/main.js",
output: {
path: __dirname + "/public",
filename: "app.js"
},
devServer: {
contentBase: "./public",
historyApiFallback: true,
inline: true,
@Ibro
Ibro / package.json
Created Feb 20, 2016
Adding webpack-dev-server dependency
View package.json
{
"name": "webpack-sample",
"version": "0.0.1",
"description": "Webpack sample - first try",
"main": "",
"scripts": {
"start": "webpack-dev-server --progress"
},
"repository": {
"type": "git",
@Ibro
Ibro / decorators-composition.ts
Last active Mar 25, 2017
TypeScript decorators composition
View decorators-composition.ts
class Test {
public name: string;
constructor(name: string) {
this.name = name;
}
@a()
@b()
@c()
View decorators.ts
export function log(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) {
console.log('target:', target);
console.log('propertyKey:', propertyKey);
console.log('descriptor:', descriptor);
// save a reference to the original method
let originalMethod = descriptor.value;
descriptor.value = function (...args: any[]) {
// pre
@Ibro
Ibro / typescript-tuple-types.ts
Last active Mar 25, 2017
TypeScript tuple types
View typescript-tuple-types.ts
let tupleType: [string, number];
tupleType = ['hey', 13];
// tupleType = [5, 'hey']; // Error - '[number, string]' is not assignable to '[string, number]'
// tupleType = ['hey', 'tuple']; // Error - '[string, string]' is not assignable to '[string, number]'
tupleType[3] = 54; // this works well because union type string | number is used for indices outside of known ones
tupleType[4] = 'test'; // works well because it can be string or number, union type
// tupleType[5] = true; // Error - Type 'true' is not assignable to type 'string | number'
@Ibro
Ibro / typescript-type-guards.ts
Last active Mar 27, 2017
Type guarding in TypeScript
View typescript-type-guards.ts
class Student {
study() {
}
}
class Professor {
teach() {
}
}
function getPerson(n: number): Student | Professor {
if (n === 1) {
@Ibro
Ibro / typescript-union-types.ts
Created Mar 27, 2017
Union Types in TypeScript
View typescript-union-types.ts
function print(text: string | string[]): string {
if (typeof text === 'string') {
return text;
}
// compiler now knows that you can use join
// and that variable type is definitely string[]
return text.join(' ');
}
@Ibro
Ibro / typescript-union-types-interfaces.ts
Created Mar 27, 2017
Union Types in TypeScript - Interfaces
View typescript-union-types-interfaces.ts
interface IStudent {
id: string;
age: number;
}
interface IWorker {
companyId: string;
}
type IUnionType = IStudent | IWorker;
@Ibro
Ibro / typescript-intersection-type-simple.ts
Created Mar 28, 2017
TypeScript - intersection types simple example
View typescript-intersection-type-simple.ts
interface IStudent {
id: string;
age: number;
}
interface IWorker {
companyId: string;
}
type A = IStudent & IWorker;
You can’t perform that action at this time.