Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does TypeORM need reflect-metadata?

I'm currently learning TypeScript with Node. Reading about TypeORM, I saw that the reflect-metadata package is needed for TypeORM to work. What is the reason for this package being needed?

like image 696
Erik Avatar asked Apr 02 '18 20:04

Erik


People also ask

Why do we use metadata reflection?

reflect-metadata Allows you to do runtime reflection on types. The native (non reflect-metadata) version of type inference is much poorer than reflect-metadata and consists only of typeof and instanceof .

What is metadata in TypeScript?

The metadata value is any possible JavaScript value. The Reflect. getMetadata returns the metadata associated with the target or its property. If no metadata is found, it returns undefined . Using these methods, you can associate any metadata with any object or its properties.

What is TypeORM in node JS?

TypeORM is an Object Relational Mapper library running in node. js and written in TypeScript. TypeScript is an improvement to JavaScript with optional typing. TypeScript is a compiled language. It is not interpreted at run-time.


1 Answers

With the reflect-metadata package you can do runtime reflection on types. Since TypeORM mostly works with decorators (like @Entity or @Column), this package is used to parse these decorators and use it for building sql queries.

The following link provides detailed information about what this package is capable of: http://blog.wolksoftware.com/decorators-metadata-reflection-in-typescript-from-novice-to-expert-part-4.

like image 120
JudgeFudge Avatar answered Nov 15 '22 10:11

JudgeFudge