outsideurimagination
outsideurimagination
Explore posts from servers
Aarktype
Created by outsideurimagination on 2/16/2025 in #questions
flatMorph in a type
I'm trying to use flatMorph to generate dynamic template literal keys for a type but it's becoming unknown.
const test = flatMorph(
Array.from({ length: 15 }, (_, i) => i + 1),
(i, v) => [`test_${i}` as const, 'string'],
);
const a = type(test)
const test = flatMorph(
Array.from({ length: 15 }, (_, i) => i + 1),
(i, v) => [`test_${i}` as const, 'string'],
);
const a = type(test)
The types are:
const test: {
[x: `test_${number}`]: string;
}

const a: Type<unknown, {}>
const test: {
[x: `test_${number}`]: string;
}

const a: Type<unknown, {}>
Why is a not preserving the type?
6 replies
CDCloudflare Developers
Created by outsideurimagination on 4/3/2024 in #pages-help
Dynamically import incompatible packages for dev only
I am currently dynamically importing a package that is incompatible in workers just during development, but the worker still won't compile when I try deploying since it still tries to get those packages. I am wondering how I can avoid that and truly just have that dependency in local development? I guess something is hoisting my dynamic import. Maybe there's a technique to make cloudflare ignore it?
let driver: Driver;
if (NODE_ENV === 'development') {
const {default: fsDriver} = await import("unstorage/drivers/fs-lite");
driver = fsDriver({ base: "./kv" })
}
let driver: Driver;
if (NODE_ENV === 'development') {
const {default: fsDriver} = await import("unstorage/drivers/fs-lite");
driver = fsDriver({ base: "./kv" })
}
1 replies
Aarktype
Created by outsideurimagination on 3/18/2024 in #questions
False recursive reference
Anyone know how I can get past this false positive claiming I'm recursively referencing process.env in its base type? Since the value is just being used to compute the base type, not in the actual base type, this should be okay.
import { type } from "arktype";

const env = type({
...(process.env.NODE_ENV === "production" && {
DATABASE_URL: 'string'
}),
});

export const assertEnv = () => env.assert(process.env);

type Env = typeof env.infer;
declare global {
namespace NodeJS {
interface ProcessEnv extends Env {}
}
}
import { type } from "arktype";

const env = type({
...(process.env.NODE_ENV === "production" && {
DATABASE_URL: 'string'
}),
});

export const assertEnv = () => env.assert(process.env);

type Env = typeof env.infer;
declare global {
namespace NodeJS {
interface ProcessEnv extends Env {}
}
}
2 replies