A
arktype3mo ago
Dimava

`string.integer.parsed` with limits

I need a simple port number, 1 < integer < 9999 Hovewer, I want to parse it from env string so I need string.integer.parse How do I make the limited parsed integer?
26 Replies
Dimava
DimavaOP3mo ago
import { type } from 'arktype'
const oneTo9999 = type('1 <= number.integer <= 9999')

const T = type({
PORT: ['string.integer.parse', '=>', oneTo9999],
})
const defaults: typeof T.in = {
PORT: 123,
}
import { type } from 'arktype'
const oneTo9999 = type('1 <= number.integer <= 9999')

const T = type({
PORT: ['string.integer.parse', '=>', oneTo9999],
})
const defaults: typeof T.in = {
PORT: 123,
}
(this doesn't work) WIW is
const T = type({
PORT: '1 < string.integer.parse < 9999 | 1 < integer < 9999'
})
const tIn: typeof T.in
const tLike = T.typedAssert({
PORT: 1234
})
const T = type({
PORT: '1 < string.integer.parse < 9999 | 1 < integer < 9999'
})
const tIn: typeof T.in
const tLike = T.typedAssert({
PORT: 1234
})
ssalbdivad
ssalbdivad3mo ago
So what is your issue?
No description
ssalbdivad
ssalbdivad3mo ago
t.in is a Type, not an inferred output It's t.infer like it has always been
Dimava
DimavaOP3mo ago
🤔 what was my issue again
Dimava
DimavaOP3mo ago
This
No description
Dimava
DimavaOP3mo ago
2.0.0-rc.6
ssalbdivad
ssalbdivad3mo ago
what is the error on T? Oh just that it's unused?
Dimava
DimavaOP3mo ago
..... Waitaminute Lemme unupdate back
ssalbdivad
ssalbdivad3mo ago
I can't repro it
Dimava
DimavaOP3mo ago
I can't repron't it Researching...
ssalbdivad
ssalbdivad3mo ago
I mean that type doesn't make any sense it's like it's not even trying to infer anything
Dimava
DimavaOP3mo ago
Okay this was tsconfig looking what exactly
ssalbdivad
ssalbdivad3mo ago
I have tested it with only strictNullChecks in tsconfig and it works So I guess you have some resolution setting that is actively breaking it
Dimava
DimavaOP3mo ago
Okay it was "moduleResolution": "node",
ssalbdivad
ssalbdivad3mo ago
But that should work I thought? Isn't that the default I know there was a problem with node resolution in a previous build so I added tests for default settings and people said their node resolution was fixed
Dimava
DimavaOP3mo ago
Okay here's repro
{
"compilerOptions": {
"lib": ["esnext"],
"strictNullChecks": true
}
}
{
"compilerOptions": {
"lib": ["esnext"],
"strictNullChecks": true
}
}
Why do I even have that lib: esnext there (╯°□°)╯︵ ┻━┻
ssalbdivad
ssalbdivad3mo ago
Why does that break it though blah
Dimava
DimavaOP3mo ago
GitHub
TypeScript/src/lib/esnext.d.ts at main · microsoft/TypeScript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - microsoft/TypeScript
ssalbdivad
ssalbdivad3mo ago
Dunno it still works fine for me with that enabled
Dimava
DimavaOP3mo ago
okay idk see you tomorrow (╯°□°)╯︵ ┻━┻
type({
LOG_SIZE_LIMIT_MB: type('string.integer.parse').pipe(type('number.integer > 0')),
)}
type({
LOG_SIZE_LIMIT_MB: type('string.integer.parse').pipe(type('number.integer > 0')),
)}
Me don't like this Why can't I just 'string.integer.parse > 0' Or at least ['string.integer.parse', '=>', 'number.integer > 0'] Or at least ['string.integer.parse', '=>', type('number.integer > 0')]
ssalbdivad
ssalbdivad3mo ago
You can use .to when piping to another type then pass the definition deirectly
Dimava
DimavaOP3mo ago
Can what?
No description
ssalbdivad
ssalbdivad3mo ago
Wtf is your type .to is only available on morphs which string.integer.parse is but it's clearly not being inferred correctly
Dimava
DimavaOP3mo ago
that 💩 magic that doesn't allow me to use stuff! It come again! (╯°□°)╯︵ ┻━┻ okay idk see you tomorrow (╯°□°)╯︵ ┻━┻
Dimava
DimavaOP3mo ago
Okay I've kleaned up my node_modules and it now work
No description
ssalbdivad
ssalbdivad3mo ago
Try that first next time your env is always doing weird shit🤣
Want results from more Discord servers?
Add your server