mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Merge pull request #27464 from overleaf/slg-filter-group-member-list
add user filter to group member list GitOrigin-RevId: 0a65ca377979de706e2e43ee024d2cee9261a121
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { Brand } from './brand'
|
||||
|
||||
/**
|
||||
* A branded type representing a string that is guaranteed to be non-empty.
|
||||
* This is a compile-time-only type and does not add any runtime overhead.
|
||||
* It's created using a type guard and is a safer alternative to a simple `string`
|
||||
* when you need to ensure the value is not an empty string ('').
|
||||
*
|
||||
* The compiler will prevent a regular `string` or an empty string literal
|
||||
* from being assigned to this type without a type assertion. The recommended way
|
||||
* to create an instance of this type is by using the {@link isNonEmptyString}
|
||||
* type guard.
|
||||
*
|
||||
* @example
|
||||
* // A function that requires a non-empty string as input
|
||||
* function greetUser(name: NonEmptyString): void {
|
||||
* console.log(`Hello, ${name}!`);
|
||||
* }
|
||||
*
|
||||
* // Use the type guard to safely call the function
|
||||
* if (isNonEmptyString("Alice")) {
|
||||
* greetUser(userInput); // This call is valid
|
||||
* } else {
|
||||
* console.error("Error: User name cannot be empty.");
|
||||
* }
|
||||
*/
|
||||
export type NonEmptyString = Brand<string, 'NonEmptyString'>
|
||||
|
||||
/**
|
||||
* A type guard to check if a string is non-empty.
|
||||
*
|
||||
* This function performs a runtime check and, if the condition is met,
|
||||
* tells the TypeScript compiler to treat the string as a {@link NonEmptyString}.
|
||||
* This is the only way to safely transition from a `string` to a `NonEmptyString`
|
||||
* type without a type assertion.
|
||||
*
|
||||
* @param {string} str - The string to check.
|
||||
* @returns {str is NonEmptyString} - A boolean indicating if the string is non-empty.
|
||||
*/
|
||||
export function isNonEmptyString(str: string): str is NonEmptyString {
|
||||
return str.length > 0
|
||||
}
|
||||
Reference in New Issue
Block a user