Unsatisfiable type

I'm trying to do this intersection, that should definitely work with typescript types, but is not working on arktype, and returning this error: Intersection of { client_id: string, code: string, grant_type: "authorization_code", redirect_uri: (In: string ) => Out<URL>, + (undeclared): delete } and { client_secret: string, code_verifier?: never, + (undeclared): delete } | { code_verifier: string, client_secret?: never, + (undeclared): delete } results in an unsatisfiable type. I've tested it in the playground and it works, but not in my code and I can't figure out why.
const secretOrVerifier = type(
{
"client_secret?": "never",
code_verifier: "string",
},
"|",
{
client_secret: "string",
"code_verifier?": "never",
},
);

export const Thing = type(
{
client_id: "string",
redirect_uri: "string.url.parse",
code: "string",
grant_type: "'authorization_code'",
},
"&",
secretOrVerifier,
);
const secretOrVerifier = type(
{
"client_secret?": "never",
code_verifier: "string",
},
"|",
{
client_secret: "string",
"code_verifier?": "never",
},
);

export const Thing = type(
{
client_id: "string",
redirect_uri: "string.url.parse",
code: "string",
grant_type: "'authorization_code'",
},
"&",
secretOrVerifier,
);
13 Replies
ssalbdivad
ssalbdivad5d ago
Hmm, could be a caching issue potentially? Is your code public or are you able to narrow it down and publish some repo so I can see what's happening?
𝘵𝘳𝘢𝘮𝘱𝘰𝘹
I just deleted the node_modules, and pnpm-lock, but the error persists. I tried creating a new react-router project, and the error is gone. Really weird Found the issue: I have a file called arktype.ts, where I use arktype/config to delete undeclared keys with
import { configure } from "arktype/config";
configure({ onUndeclaredKey: "delete" });
import { configure } from "arktype/config";
configure({ onUndeclaredKey: "delete" });
after commenting those lines, it started working
ssalbdivad
ssalbdivad5d ago
Ahh okay, that makes sense. If you want to add more properties to an object with an undeclared config, you should use .merge instead of .and (generally better for combining objects anyways)
𝘵𝘳𝘢𝘮𝘱𝘰𝘹
another unrelated question, but how do I create an type from object in arktype? Where I have like:
const options = {
foo: "foo",
bar: "bar",
} as const;

const optionsSchema = type(options) // : "'foo' | 'bar'"
const options = {
foo: "foo",
bar: "bar",
} as const;

const optionsSchema = type(options) // : "'foo' | 'bar'"
ssalbdivad
ssalbdivad5d ago
ArkType
ArkType Docs
TypeScript's 1:1 validator, optimized from editor to runtime
𝘵𝘳𝘢𝘮𝘱𝘰𝘹
I'm asking this because I already used type.enumerated(Object.values(options)), that results in "('foo' | 'bar')[]", but for some reason, it says that the input must include all the options available, and not one of
ssalbdivad
ssalbdivad5d ago
It should be type.enumerated(...Object.values(options))
𝘵𝘳𝘢𝘮𝘱𝘰𝘹
wouldn't it turn into just "'foo' | 'bar'"? Because I'm actually aiming for it to be an array with one of the options
ssalbdivad
ssalbdivad5d ago
Then you can chain .array() off that
𝘵𝘳𝘢𝘮𝘱𝘰𝘹
got it, thank you hey, I was thinking if there's a way to use .merge without using the fluent way, I know that type.module you can use the Merge generic but is there a way in the same way that you can use "&" and "|"?
ssalbdivad
ssalbdivad2d ago
There's not a direct equivalent to & or | in this case. You can use the "..." key version of the syntax which would allow you to create a serializable version of the definition
𝘵𝘳𝘢𝘮𝘱𝘰𝘹
also, is there a way that I can use typesafe inputs while validating?
ssalbdivad
ssalbdivad2d ago
MyType.from will check what you pass directly

Did you find this page helpful?