figma-api
figma-api copied to clipboard
GetFileNodesResult document is incorrect
Hello!
I was working with this library, and it seems like the "document" that we return from api.getFileNodes
doesn't reflect the actual data returned:
export interface GetFileNodesResult {
name: string,
lastModified: string,
thumbnailUrl: string,
version: string,
err?: string,
nodes: {
[nodeId: string]: {
document: Node<'DOCUMENT'>, // <-- this one!
components: { [nodeId: string]: Component },
schemaVersion: number,
styles: { [styleName: string]: Style },
}|null
},
}
In actuality, I think this should be a more generic Node
type, something like:
export interface GetFileNodesResult {
name: string,
lastModified: string,
thumbnailUrl: string,
version: string,
err?: string,
nodes: {
[nodeId: string]: {
document: Node<NodeType>, // <-- here
components: { [nodeId: string]: Component },
schemaVersion: number,
styles: { [styleName: string]: Style },
}|null
},
}
or, if you wanted to add the ability to customize what's returned based on the IDs passed to getFileNodes
, you could use generics like this:
export interface GetFileNodesResult<T extends Node<NodeType>> {
name: string,
lastModified: string,
thumbnailUrl: string,
version: string,
err?: string,
nodes: {
[nodeId: string]: {
document: T, // <-- here!
components: { [nodeId: string]: Component },
schemaVersion: number,
styles: { [styleName: string]: Style },
}|null
},
}
// ...
function getFileNodesApi<T extends Node<NodeType> = Node<NodeType>>( // <-- uses all node types by default
//...
): : Promise<GetFileNodesResult<T>>