{}
as a type1227 * @param userData Custom data that is attached to the commit data. The data must be JSON.stringifyable.
1228 * @returns New commit object.
1229 */
1230 async createCommit(index: Index, message: string, opts?: {allowEmpty?: boolean}, tags?: string[], userData?: {}): Promise<Commit> {1231 let tree: TreeDir = null;
1232 let commit: Commit = null;
1233 if (opts?.allowEmpty) {
Some builtin types have aliases, some types are considered dangerous or harmful. It's often a good idea to ban certain types to help with consistency and safety.
It includes a set of "best practices", intended to provide safety and standardization in your codebase:
Don't use the upper-case primitive types, you should use the lower-case types for consistency.
Avoid the Function
type, as it provides little safety for the following reasons:
new
keyword.Avoid the Object
and {}
types, as they mean "any non-nullish value".
Avoid the object
type, as it is currently hard to use due to not being able to assert that keys exist.
// use of upper-case primitives
const str: String = 'foo';
const bool: Boolean = true;
const num: Number = 1;
const symb: Symbol = Symbol('foo');
// use a proper function type
const func: Function = () => 1;
// use safer object types
const lowerObj: object = {};
const capitalObj1: Object = 1;
const capitalObj2: Object = { a: 'string' };
const curly1: {} = 1;
const curly2: {} = { a: 'string' };
// use lower-case primitives for consistency
const str: string = 'foo';
const bool: boolean = true;
const num: number = 1;
const symb: symbol = Symbol('foo');
// use a proper function type
const func: () => number = () => 1;
// use safer object types
const lowerObj: Record<string, unknown> = {};
const capitalObj1: number = 1;
const capitalObj2: { a: string } = { a: 'string' };
const curly1: number = 1;
const curly2: Record<'a', string> = { a: 'string' };