The infer
keyword only works within conditional types. It defines the type depending of another one.
Some use cases:
- extract type from promise
- extract function return type
- extract multiple candidates
A minimal and simple JSON schema. The syntax is actually easy 👍
Creational
Singleton
Type of object that can be instantiated once
In Typescript, just use a global object, so you don't have the boilerplate.
Prototype
Object.getPrototypeOf
Builder
Build object step by step through different methods instead of using many parameters
Factory
Determine which object to instantiate
Structural
Facade
Simplified to hide low-level details of a system
Proxy
Reactivity system of Vue :D
Replace an original object and do some side effects
Advantage: allow user to work with the proxy just like the original object but it can trigger side effects behind the scene.
Proxy are also used when there is a large object that would be expensive to duplicate in memory.
Behavioral
Iterator
Traverse through a collection of objects.
A pull based system.
An object with a next()
method in javascript that returns a { done: boolean; value: T }
.
Observer
Allow many objects to subscribe to events that are broadcast by another object.
A Subject where other objects subscribe to it and triggers their method when the subject notify
Mediator
In case of many to many relationships, one object is a coordinator between them.
Middlewares are an example of mediator.
State
What is the difference between state and strategy pattern?
Documentation that generates code that is then used in the project :)
Built with Rust and use the deno runtime.
Chiselstrike handles everything in the backend :) Can be tested someday
The way to generate types from vue 3 components.
After some hours searching about how to generate types for the vue library components, this plugin for vite solved my problem.
A typescript enumeration containing all http status codes
A description of a modern website architecture. It uses a bunch of modern technologies, and the author explains why they are useful in its case.
The more I follow the Deno project and its community, the more I think it would be easier to use Typescript and the environment of Deno to write scripts.
Python is not so much robust without types. The amount of time my script logic was correct, but I miss the type of some variable, causing a xx minute time of debugging. The type annotations are currently complex to use and overkill for scripts, where typescript shines.
Et une application tournant sous électron avec une BDD SQLite en typescript bien propre, c'est partiii.
Ou un programme Deno / NodeJS
A function that returns a type such as
asserts value is NonNullable<T>
I find Vite to be a good compromise between having the benefits of TS and the slow build step. Use es-build to transpile and does not do type checking since it passes that responsibility onto the IDE.
Totally agree with this comment !
It is still possible to run the type checker all in once if needed.
True Myth provides standard, type-safe wrappers and helper functions to help help you with two extremely common cases in programming:
- not having a value
- having a result where you need to deal with either success or failure
Ok why not ? But is this needed ?
And a better pattern instead
We can define the case of the properties (PascalCase, SnakeCase, KebabCase, CamelCase) since 4.1
Rule: If a type parameter only appears in one location, strongly reconsider if you actually need it.
A good news ! Typescript is supported in svelte
type Subset<Parent, Sub extends Parent> = Sub;
type IconName = 'cars' | 'mars' | 'truck' | 'warning'
type VehicleIconName = Subset<IconName, 'cars' | 'truck' | 'invalidName'>