Bobakanoosh
Bobakanoosh
Explore posts from servers
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
For posterity, finally got everything working, last part was having a default value in the event the parsing failed. For that I just needed to use the type type.Any<TData>['inferOut'] Thanks again!
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
Yeah those are some good "basics" that I think would go a long way. Appreciate all your work!!
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
And TBH that stuff will also happen if you're e.g. writing a Zod schema and wanting to pass it to your own generics based on constraints
Yeah I ran into this when making some frontend form/form input components
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
It's definetly come leaps and bounds from even a few weeks ago, I see the progress 🙂
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
was weeks ago
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
I might've searched the discord tbh i forget
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
I keep wanting to use this lib because I see the potential but it can be demotivating losing hours to it :/ (as it usually goes with complex types though)
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
Admittedly would be nice, I know you're super busy though 😂 even if they're not docs but moreso "recipes". Common use-cases that cover mechanics of the library that aren't super evident/easy to think of at first. e.g. type for password and confirmPassword. I figured that out eventually but a recipe of having one field rely on another of it's own type would've helped a ton.
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
hmmmm okay trying that 1 sec there's a few other things I haven't included in my snippets thus far lol
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
Here's the full snippet:
class SomeClass<TData extends any> {
public constructor(public schema: type.Any<TData>) {
}
}

const $ = scope({
config: () =>
$.type("string.json.parse").to({
windowMeta: "Record<string, windowMeta>"
}),
windowMeta: {
"position?": {
x: "number",
y: "number"
}
}
})

const types = $.export()

type UserConfig = typeof types.config.infer;

class SomeParentClass extends SomeClass<UserConfig> {
constructor() {
super(types.config);
}
}
class SomeClass<TData extends any> {
public constructor(public schema: type.Any<TData>) {
}
}

const $ = scope({
config: () =>
$.type("string.json.parse").to({
windowMeta: "Record<string, windowMeta>"
}),
windowMeta: {
"position?": {
x: "number",
y: "number"
}
}
})

const types = $.export()

type UserConfig = typeof types.config.infer;

class SomeParentClass extends SomeClass<UserConfig> {
constructor() {
super(types.config);
}
}
error is:
Type '(In: string & { " attributes": { base: string; attributes: Nominal<"json">; }; }) => To<{ windowMeta: Record<string, { position?: { x: number; y: number; } | undefined; }>; }>' is not assignable to type '{ windowMeta: { [x: string]: { position?: { x: number; y: number; } | undefined; }; }; }'
Type '(In: string & { " attributes": { base: string; attributes: Nominal<"json">; }; }) => To<{ windowMeta: Record<string, { position?: { x: number; y: number; } | undefined; }>; }>' is not assignable to type '{ windowMeta: { [x: string]: { position?: { x: number; y: number; } | undefined; }; }; }'
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
Yeah I end up passing $.export().config to the class's super
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
so you can use the schema within the group
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
thats what .export() is for right?
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
Right yeah but now it takes a string and outputs an object
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
which I kinda get since it's not taking an object any more
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
This does break the type.Any<TData> from the other example though 🙁
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
very nice ok
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
ahhh self referencing kinda
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Using scope with morphs
Explanations are helpful so you're all good lol
59 replies
Aarktype
Created by Bobakanoosh on 11/15/2024 in #questions
Passing an exported scope to a function (Type 'string' is not assignable to type 'never')
I was refactoring some code while doing this and realizing I actually have the wrong type, gonna make a new thread for this other issue..
16 replies