For object literals without type annotations, many TypeScript features don't work. Contrived example:
type User = { name: string; age: number };
const makeUser = () => ({ name: 'bob', age: 123 });
import { TSESLint, TSESTree } from '@typescript-eslint/utils'; | |
import * as tsutils from 'tsutils'; | |
import * as ts from 'typescript'; | |
import { getChecker, getParserSvc, ruleCreator } from '../utils'; | |
export const RequireObjectTypeAnnotations = ruleCreator({ | |
defaultOptions: [], | |
meta: { | |
docs: { |
Given this JSON + ICU Message:
{
"uploaded": {
"message": "Your <photoLink>photo</photoLink> has been uploaded.",
"backend": "tsx"
}
}
const { getTypeServices } = require('eslint-etc'); | |
const { | |
ESLintUtils, | |
TSESTree, | |
TSESLint, | |
} = require('@typescript-eslint/experimental-utils'); | |
const ruleCreator = ESLintUtils.RuleCreator( | |
(_name) => | |
// This should be the URL of the docs for this rule, but since this is a custom/local rule, we |
#!/bin/bash | |
# Exit immediately if a command exits with a non-zero status, amongst other improvements | |
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ | |
set -eux | |
# | |
# Example usage: | |
# ./prettier-diff.sh --no-index my-minified-file-before.js my-minified-file-after.js | |
# |
return (0, a.jsxs)( | |
ae.im, | |
{ | |
id: s, | |
style: { marginLeft: -ve }, | |
popoverProps: c, | |
children: [ | |
(0, a.jsx)( | |
ae.xz, | |
{ showDropdownSymbol: !0, className: (0, ne.Bt)({}), children: t(d) }, |
import { pipe } from 'fp-ts/function'; | |
import * as NonEmptyArray from 'fp-ts/NonEmptyArray'; | |
import * as O from 'fp-ts/Option'; | |
const runMain = () => { | |
require('./main'); | |
}; | |
const createTimeoutPromise = (timeout: number): Promise<void> => | |
new Promise<void>((resolve) => |
In our E2E tests, when the test runner navigates through the site, we don't want to make real API requests but rather we want to mock these requests so that we can easily test many different scenarios, and so that our tests are more resilient and less likely to flake if API is suffering any downtime.
Up until now, this has been achieved by "mocking the fetch function". For example:
function reverseFormatNumber(val,locale){ | |
var parts = new Intl.NumberFormat(locale).formatToParts(1111.1); | |
var group = parts.find(part => part.type === 'group').value; | |
var decimal = parts.find(part => part.type === 'decimal').value; | |
var reversedVal = val.replace(new RegExp('\\' + group, 'g'), ''); | |
reversedVal = reversedVal.replace(new RegExp('\\' + decimal, 'g'), '.'); | |
return Number.isNaN(reversedVal)?0:+reversedVal; | |
} | |
console.log(reverseFormatNumber('1,234.56','en')); |
// @ts-check | |
const treeify = require('treeify'); | |
/** | |
* @param {import('webpack').StatsCompilation} stats | |
* @param {string | number} id | |
*/ | |
const getModuleById = (stats, id) => stats.modules.find((module) => module.id === id); |