isShapeId
See source codeType guard to check if a string is a valid shape ID.
function isShapeId(id?: string): id is TLShapeId
Example
const id = 'shape:abc123'
if (isShapeId(id)) {
const shape = store.get(id) // TypeScript knows id is TLShapeId
}
// Check user input
function selectShape(id: string) {
if (isShapeId(id)) {
editor.selectShape(id)
} else {
console.error('Invalid shape ID format')
}
}
Parameters
Name | Description |
---|---|
|
The string to check |
Returns
id is TLShapeId
True if the string is a valid shape ID, false otherwise
Prev
isShapeNext
toRichText