Skip to content

Commit

Permalink
🐛 Remove slow-types not allowd in JSR
Browse files Browse the repository at this point in the history
JSR does not allow slow types. See https://jsr.io/docs/about-slow-types

```
error: TS1170 [ERROR]: A computed property name in a type literal must refer to an expression whose type
is a literal type or a 'unique symbol' type.
  [metadataKey]: T;
  ~~~~~~~~~~~~~
    at file:///Users/alisue/ghq/github.com/lambdalisue/deno-unknownutil/metadata.ts:9:26

TS2304 [ERROR]: Cannot find name 'metadataKey'.
  [metadataKey]: T;
   ~~~~~~~~~~~
    at file:///Users/alisue/ghq/github.com/lambdalisue/deno-unknownutil/metadata.ts:10:4

Found 2 errors.
```
  • Loading branch information
lambdalisue committed Apr 6, 2024
1 parent a4b91de commit acc3c2f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions metadata.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { Predicate } from "./is/type.ts";
import { inspect } from "./inspect.ts";

const metadataKey = "__unknownutil_metadata";

/**
* A type that has metadata.
*/
export type WithMetadata<T> = {
[metadataKey]: T;
__unknownutil_metadata: T;
};

/**
Expand All @@ -21,7 +19,7 @@ export type GetMetadata<T> = T extends WithMetadata<infer M> ? M : never;
export function getMetadata<T>(v: unknown): T | undefined {
if (v == null) return undefined;
// deno-lint-ignore no-explicit-any
return (v as any)[metadataKey];
return (v as any).__unknownutil_metadata;
}

/**
Expand All @@ -44,7 +42,7 @@ export function setPredicateFactoryMetadata<
): P & WithMetadata<M> {
let cachedName: string | undefined;
return Object.defineProperties(pred, {
[metadataKey]: {
__unknownutil_metadata: {
value: metadata,
configurable: true,
},
Expand Down

0 comments on commit acc3c2f

Please sign in to comment.