mirror of https://github.com/laurent22/joplin.git
16 lines
413 B
TypeScript
16 lines
413 B
TypeScript
|
|
const getProperty = (object: unknown, propertyName: string) => {
|
|
if (typeof object !== 'object' || object === null) {
|
|
throw new Error(`Cannot access property ${JSON.stringify(propertyName)} on non-object`);
|
|
}
|
|
|
|
if (!(propertyName in object)) {
|
|
throw new Error(`No such property ${JSON.stringify(propertyName)} in object`);
|
|
}
|
|
|
|
return object[propertyName as keyof object];
|
|
};
|
|
|
|
export default getProperty;
|
|
|