Archive Tags About

Nikša Fantela

Javascript (Typescript) Developer from Croatia, currently deep into Angular & RxJS

  • Jun 9
    Rebuilding Typescript utility types

    If like me you ever wondered how to recreate some Typescript magic yourself the following tips are for you. There are many utility types so we will narrow down to some interesting ones. Utility types we will reconstruct Partial Readonly Pick<T,K> Exclude<T,K> Extract<T,K> NonNullable Things to note in the following examples is first : that typescript removes never so bascicaly type MyCustomType = string | never | boolean; will equal to string | boolean.

  • Jun 4
    Dependency Injection Tricks in Angular

    Here are few tricks that I picked up along the way in everyday Angular use and study. Along with usual provideIn:{} and dependency injection from documentation examples, there is as usual - more to the story. Providing dependencies - the alternate ways. Declaring the suspects: A service that will be the dependency we are injecting: LoggerService Parent component that will provide service Directive: ProvideDirective that will also provide aforementioned service.

  • Jun 1
    Multiple inheritance with Typescript and class mixins

    The Problem : extending more than 1 class in Typescript This is common use case scenario in OOP hovewer in Typescript & Javascript a slight hack is required. The solution: Mixins Are functions that return class constructors so let us dive into example: Mixin file In the Gist above, we first declare Class Constructor type that will implement our interfaces which will basically define types (class) constructors that will be returned (Disabled, HasValue).

  • May 25
    Typescript custom error messages with Conditional types

    Sometimes when building code that uses custom Types we want to limit those custom types e.g. give the developer some kind of custom warning when he is trying to use our code. A good example is to create custom error type messages using typescript conditional types. Types…types everywhere.. Forbide Arrays and provide custom err message type In this simple Gist we first declare our conditional type ArraysNotAllowed. It will accept custom type and error message type we want to display.

  • May 10
    Fixing Circular Imports in Angular using Injection Tokens

    This is not something directly related to Angular but programming in general. Most common use cases involve parent directive/component querying for children via @ContentChildren() and later on those same child components injecting aforementioned parent. Let us set up our suspects There are three things we will need: Injection token and interface Parent directive that will be used as element here (not attribute selector): <parent-dir>... child components here... </parent-dir> .

← Newer Posts
github twitterbird

Copyright © 2020 Nikša Fantela

E-mail: nfantela.dev@gmail.com

Powered by Hugo