{"id":16384799,"url":"https://github.com/saber2pr/reflect","last_synced_at":"2025-08-19T13:13:57.456Z","repository":{"id":108571463,"uuid":"185553258","full_name":"Saber2pr/reflect","owner":"Saber2pr","description":":eight_spoked_asterisk: Typescript Reflector.","archived":false,"fork":false,"pushed_at":"2019-05-29T12:11:51.000Z","size":21,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-22T03:26:42.300Z","etag":null,"topics":["metadata","reflect","typescript"],"latest_commit_sha":null,"homepage":"https://saber2pr.top/#/blog/Reflect%E5%8F%8D%E5%B0%84%E5%8E%9F%E7%90%86/reflect-metadata%E5%AE%9E%E7%8E%B0%E5%8F%8A%E5%85%B6%E5%8E%9F%E7%90%86","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Saber2pr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-05-08T07:18:52.000Z","updated_at":"2020-08-19T01:56:27.000Z","dependencies_parsed_at":"2023-07-18T16:21:38.000Z","dependency_job_id":null,"html_url":"https://github.com/Saber2pr/reflect","commit_stats":null,"previous_names":["saber2pr/-saber2pr-reflect"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Saber2pr/reflect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saber2pr%2Freflect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saber2pr%2Freflect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saber2pr%2Freflect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saber2pr%2Freflect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Saber2pr","download_url":"https://codeload.github.com/Saber2pr/reflect/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saber2pr%2Freflect/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265751194,"owners_count":23822732,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["metadata","reflect","typescript"],"created_at":"2024-10-11T04:12:35.361Z","updated_at":"2025-07-18T11:34:17.865Z","avatar_url":"https://github.com/Saber2pr.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @saber2pr/reflect\n\n\u003e Typescript Reflector.\n\n\u003e `PASS: 已通过所有官方测试用例`\n\n```bash\n# from npm\nnpm install @saber2pr/reflect\n\n# from github\ngit clone https://github.com/Saber2pr/reflect.git\n```\n\n---\n\n# Reflect-metadata\n\n```ts\n@Reflect.metadata('inClass', 'A')\nclass Test {\n  constructor(private test?: Test) {}\n  @Reflect.metadata('inMethod', 'B')\n  public hello(): string {\n    return 'hello world'\n  }\n}\n\nconsole.log(Reflect.getMetadata('inClass', Test)) // 'A'\nconsole.log(Reflect.getMetadata('design:paramtypes', Test)) // [ [Function: Test] ]\nconsole.log(Reflect.getMetadata('inMethod', new Test(), 'hello')) // 'B'\n```\n\n## What is Reflect-metadata?\n\nReflect Metadata 是 ES7 的一个提案，它主要用来在声明的时候添加和读取元数据。\n\n[\u003e\u003e Reflect Metadata](https://jkchao.github.io/typescript-book-chinese/tips/metadata.html#reflect-metadata)\n\n---\n\n## API\n\n1. Reflect.defineMetadata\n\n\u003e 定义元数据\n\n```ts\nfunction defineMetadata(\n  metadataKey: MetadataKey,\n  metadataValue: MetadataValue,\n  target: Object,\n  propertyKey?: string\n): void\n```\n\n2. Reflect.getMetadata\n\n\u003e 获取元数据\n\n```ts\nfunction getMetadata\u003cT\u003e(\n  metadataKey: MetadataKey,\n  target: Object,\n  propertyKey?: string\n): T\n```\n\n3. Reflect.getMetadataKeys\n\n\u003e 获取所有元数据键\n\n```ts\nfunction getMetadataKeys(target: Object, propertyKey?: string)\n```\n\n4. Reflect.metadata\n\n\u003e 元数据装饰器\n\n```ts\nfunction metadata(metadataKey: MetadataKey, metadataValue: MetadataValue)\n```\n\n`! tsconfig 需开启 experimentalDecorators: true`\n\n## 元数据设计键\n\n`! tsconfig 需开启 emitDecoratorMetadata: true`\n\n1. design:type\n\n2. design:paramtypes\n\n3. design:returntype\n\n[\u003e\u003e Reflect 反射规则](https://rbuckton.github.io/reflect-metadata/#syntax)\n\n---\n\n## start\n\n```bash\nnpm install\n```\n\n```bash\nnpm start\n\nnpm test\n```\n\n\u003e Author: saber2pr\n\n---\n\n## develope and test\n\n\u003e you should write ts in /src\n\n\u003e you should make test in /src/test\n\n\u003e export your core in /src/index.ts!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaber2pr%2Freflect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaber2pr%2Freflect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaber2pr%2Freflect/lists"}