type Require = {} extends { a: string } ? true : false // false
type OptionalProperty = {} extends { a?: string } ? true : false // true
type OptionalValue = {} extends { a: string | undefined } ? true : false
type Index = {} extends { [x: string]: any } ? true : false // true
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* _Explicitly declare modifications_ to an existing object type via a fluent interface which yields a mapping function | |
* from the original data type to the type derived from the modification commands. | |
* | |
* The value over authoring a simple mapping function directly | |
* * harder to make a mistake due to the explicit nature | |
* * easier to read. | |
* | |
* This is _not_ production quality code but rather a _proof of concept_ gist for applying conditional/mapped | |
* types to mapper generation. A real-world usage might involve also generating the type-guard function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Imagine a Fluent Builder where some subset of the fluent methods are valid to call | |
* * after one or more fluent methods have been called | |
* * before one or more fluent methods have been called | |
* * limited number of times. | |
* | |
* There is no way to enforce such constraints in statically typed languages such as C++, C# or Java when using a single builder | |
* class/interface. Developers would need to author many interfaces to represent the different shapes and would likely need to | |
* author many versions of the builder itself (proxies with a specific signature delegating to an underlying source builder). | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const PLUGIN_NAME = "MutateRuntimePlugin"; | |
class MutateRuntimePlugin { | |
/** | |
* | |
* @param {FederationDashboardPluginOptions} options | |
*/ | |
constructor(options) {} | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-console */ | |
const resolver = require('babel-plugin-module-resolver') | |
const resolve = require('enhanced-resolve') | |
const path = require('path') | |
const { DEBUG, BABEL_ENV, NODE_ENV, TARGET } = process.env | |
const isProduction = NODE_ENV === 'production' | |
const isServer = TARGET === 'server' | |
const resolverTs = resolve.create.sync({ | |
extensions: ['.ts', '.tsx', '.js', '.json'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>join vs concat when dealing with very long lists of single-character strings</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
<script src="./suite.js"></script> | |
</head> | |
<body> | |
<h1>Open the console to view the results</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cache = new Map(); | |
let pending = new Map(); | |
function fetchTextSync(url) { | |
if (cache.has(url)) { | |
return cache.get(url); | |
} | |
if (pending.has(url)) { | |
throw pending.get(url); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Так мы пушим нотификации из любого места системы, статическое свойство класса. | |
NotificationManager.addMessage({ | |
id?: number | string, | |
content: React.Node, | |
timeout?: number, | |
onClose?: (event: SyntheticEvent<HTMLElement>) => void | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>(key in object) vs. (object[key] !== void 0) vs. object.hasOwnProperty(key)</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
<script src="./suite.js"></script> | |
</head> | |
<body> | |
<h1>Open the console to view the results</h1> |
NewerOlder