Skip to content

Instantly share code, notes, and snippets.

@fvilante
fvilante / tube2.ts
Created January 21, 2020 18:13
Draft pseudo-type and message
// ===== PseudoType ==========
export type PseudoType<A> = {
readonly kind: 'PseudoType'
readonly __UNSAFE__TYPE: A //ATTENTION: type trick (at run-time is undefined, but at static-time is A)
}
export const PseudoType = <A>():PseudoType<A> => ({kind: 'PseudoType', __UNSAFE__TYPE: undefined as unknown as A})
@fvilante
fvilante / Arbitrary-Type-Parameter.ts
Last active January 21, 2020 18:30
Category Theory Study - 1) Static-Land Higher Kinded implementation attempt 2) A 'how-many-type-parameters' identifier propose
// An idea for arbitrary type-parameters. (see bellow 'InferTArgs')
// === Type Class ===
type TypeClass0<K extends string> = {
readonly kind: 'TypeClass'
readonly __TypeClassName: K
readonly __0: undefined
}
@fvilante
fvilante / myOnlineCode.ts
Last active December 29, 2019 10:01
Deno test - Online code to be imported
export const mymessage = `Hi! I'm a text from an online source` as const
@fvilante
fvilante / mytest.ts
Last active December 17, 2019 01:00
Typescript generics and subtypem
// Code used to answer bellow stackoverflow question:
// https://stackoverflow.com/a/59363875/8233039
// super class
type _Super<T> = {
readonly prop1: `bar`
readonly propT: T
}
const _super: _Super<string> = {
@fvilante
fvilante / example.ts
Created December 15, 2019 06:23
css pre-processor using TS lang
// study on using typescript as a host language to pre-process CSS
import { Either, Left, Right } from "../monads/either";
import { Maybe, Just, Nothing } from "../monads/maybe";
type PX = {
readonly kind: 'px'
readonly value: number
}
@fvilante
fvilante / gist:7e5b468b77e21fdc811969b2020ef131
Created December 3, 2019 14:56
Can Typescript perform run-time check at compile-time ?
// Here we will put the solution.
// But before let's have a talk bellow.
@fvilante
fvilante / InterfaceIntrospection.ts
Last active July 31, 2019 21:06
Utility type to introspect an interface
// Author: Flavio
type __PairList<T> = {
[Key in keyof T]: {
readonly key: Key
readonly value: T[Key]
}
}
type __Pair<T> = __PairList<T>[keyof T]
@fvilante
fvilante / StaticDriver.ts
Last active July 29, 2019 13:21
A fully static driver configuration
import { CmppParamType, Milimeter, Space, Speed, Acceleration, MilimeterPerSecond, MilimeterPerSquareSecond, Pulse } from './application-types'
import { mapObjectIndexed } from '@nextrobot/core-utils';
//import { ParamMemmap } from './memmap-base';
// drive instance
// core
type AnyEntry = { readonly type: unknown }
@fvilante
fvilante / groupBy.ts
Last active June 27, 2019 19:56
groupBy
let seniors = [
{
"id": 1,
"name": "Jack",
"active": true,
"level": "senior"
},
{
"id": 2,
@fvilante
fvilante / deno_test.ts
Last active May 29, 2019 05:01
Deno test
// Just a test of Deno
const aTable = { deno: 'Typescript', grupo: 'Typescript', nome: 'Flavio' }
console.log()
console.table(aTable)
console.log()