Skip to content

Instantly share code, notes, and snippets.

View vjau's full-sized avatar

Vincent Jaubert vjau

View GitHub Profile
@vjau
vjau / gist:0d3b1b72bb4ee632b18a770c18870ad4
Created March 11, 2025 22:29
Typescript utility types
type NullToOptional<K> = {
[key in keyof K as null extends K[key] ? key : never]?: Exclude<K[key], null>
} & {
[key in keyof K as null extends K[key] ? never: key]: K[key]
}
type OptionalToNullable<T> = {
[K in keyof T as undefined extends T[K] ? K : never]-?: T[K] | null; // Convert optional properties to mandatory nullable
} & {
[K in keyof T as undefined extends T[K] ? never : K]: T[K]; // Keep non-optional properties unchanged
@vjau
vjau / isExactOptional.ts
Created September 16, 2023 13:01
Utility Typescript Type to know when exactOptionalPropertyTypes is set
type _Intersect = {a?:number} & {a:number|undefined};
//state of exactOptionalPropertyTypes
type IsExactOptional = _Intersect["a"] extends Exclude<_Intersect["a"], undefined> ? true : false;
@vjau
vjau / Exemple.js
Last active January 20, 2017 03:52
nigthwatch command to fake Date in the browser. Put this in a commands folder and set the folder name in nightwatch.json "custom_commands_path" : "./commands",
module.exports = {
"we go on the page": function(browser){
browser
.url("http://localhost:3000")
.waitForElementVisible("#stuff", 10000)
.assert.title("MyPage")
},
"we fake the Date": function(browser){
browser
.fakeDate(new Date(2001, 1, 1).getTime()) //DONE !