OnkelTem
OnkelTem
Explore posts from servers
Aarktype
Created by OnkelTem on 10/14/2024 in #questions
Multiple @ark registries detected
I'm receiving this error in a Nextjs app:
Multiple @ark registries detected. This can lead to unexpected behavior.
Multiple @ark registries detected. This can lead to unexpected behavior.
I use it in my project once:
import { type } from 'arktype'

export const envSchema = type({
moduleId: 'string',
moduleMode: 'string | undefined',
})

export type EnvSchema = typeof envSchema.infer
import { type } from 'arktype'

export const envSchema = type({
moduleId: 'string',
moduleMode: 'string | undefined',
})

export type EnvSchema = typeof envSchema.infer
Ideas? Version: 2.0.0-rc.15
26 replies
CC#
Created by OnkelTem on 5/27/2024 in #help
DrawString doesn't update text / Windows Forms
Hi. I'm new to C# development. I create a control on a form and want to print its ClientRectangle. Whenever I resize the parent form, OnPaint gets called but text doesn't change. Yet the console message is of course changing. Why it happens?
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(Brushes.Black, ClientRectangle);
Console.WriteLine($"-->{ClientRectangle}");
e.Graphics.DrawString($"==>{ClientRectangle}", Font, Brushes.White, ClientRectangle);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(Brushes.Black, ClientRectangle);
Console.WriteLine($"-->{ClientRectangle}");
e.Graphics.DrawString($"==>{ClientRectangle}", Font, Brushes.White, ClientRectangle);
}
18 replies
Aarktype
Created by OnkelTem on 10/17/2023 in #questions
ParseError: '3.0' was parsed as a number but could not be narrowed to a literal value.
I'm not sure yet, where does this come from, but does it say anything to you?
/projects/custom/hfl/node_modules/arktype/dist/cjs/utils/errors.js:25
throw new ParseError(message);
^
ParseError: '3.0' was parsed as a number but could not be narrowed to a literal value. Avoid unnecessary leading or trailing zeros and other abnormal notation
at throwParseError (/projects/custom/hfl/node_modules/arktype/dist/cjs/utils/errors.js:25:11)
at parseWellFormed (/projects/custom/hfl/node_modules/arktype/dist/cjs/utils/numericLiterals.js:5
...
/projects/custom/hfl/node_modules/arktype/dist/cjs/utils/errors.js:25
throw new ParseError(message);
^
ParseError: '3.0' was parsed as a number but could not be narrowed to a literal value. Avoid unnecessary leading or trailing zeros and other abnormal notation
at throwParseError (/projects/custom/hfl/node_modules/arktype/dist/cjs/utils/errors.js:25:11)
at parseWellFormed (/projects/custom/hfl/node_modules/arktype/dist/cjs/utils/numericLiterals.js:5
...
21 replies
Aarktype
Created by OnkelTem on 10/17/2023 in #questions
CJS/ESM issue with arktype
I installed arktype. It's a ESM thing, and it broke my building process. To fix it, I had to switch to building with babel and had to set these values in tsconfig.json::
"module": "ES2015",
"moduleResolution": "Bundler"
"module": "ES2015",
"moduleResolution": "Bundler"
However, now ts-node stopped working and hence - mocha and all my tests written in TS:
import { Yandex } from './clients';
^^^^^^
SyntaxError: Cannot use import statement outside a module
import { Yandex } from './clients';
^^^^^^
SyntaxError: Cannot use import statement outside a module
Any ideas?
68 replies
Aarktype
Created by OnkelTem on 10/16/2023 in #questions
The inferred type of '... cannot be named without a reference to '../../../../node_modules/arktype/
I receive this strange message:
src/clients/client-amazon.ts:76:3 - error TS2742: The inferred type of 'get' cannot be named without a reference to '../../../../node_modules/arktype/dist/types/scopes/type'. This is likely not portable. A type annotation is necessary.
src/clients/client-amazon.ts:76:3 - error TS2742: The inferred type of 'get' cannot be named without a reference to '../../../../node_modules/arktype/dist/types/scopes/type'. This is likely not portable. A type annotation is necessary.
What's weird is that I don't see it in VSCode when editing code, but only when attepmting to build the project. Here is the code it's referrencing:
get<K extends keyof Config>(name: K) {
return config$$[name].assert(this.#config[name]);
}
get<K extends keyof Config>(name: K) {
return config$$[name].assert(this.#config[name]);
}
Here config$$ is a scope. How to properly type it?
67 replies
Aarktype
Created by OnkelTem on 10/15/2023 in #questions
Need help with typing scope output properly
I've got one crazy idea to declare types as scopes to access validators independently
27 replies
Aarktype
Created by OnkelTem on 10/15/2023 in #questions
non-empty string - how to?
How to declare a schema with 'string' type but... not empty, i.e. which is banning ""?
58 replies
Aarktype
Created by OnkelTem on 10/13/2023 in #questions
How to incorporate existing type?
I have a type imported from a third-party API and I'd like to build it in into my ark type:
import { Foo } from 'fancy-api'

const schema = type({
foo: // how to put Foo here?
})
import { Foo } from 'fancy-api'

const schema = type({
foo: // how to put Foo here?
})
86 replies
Aarktype
Created by OnkelTem on 10/11/2023 in #questions
How to declare an optional schema?
I wonder if it's possible to define a schema that is ok if data is undefined. E.g. in:
declare function foo(a?: string)v void
declare function foo(a?: string)v void
how to declare a schema for a?
26 replies
Aarktype
Created by OnkelTem on 10/11/2023 in #questions
Can scopes validate?
Can scopes validate or they are only a collection of types?
10 replies
Aarktype
Created by OnkelTem on 10/11/2023 in #questions
How to properly make a property of a class type?
I tried this:
class TokenManager {}
const params = type({
tokenManager: type(['instanceof', TokenManager]),
})
class TokenManager {}
const params = type({
tokenManager: type(['instanceof', TokenManager]),
})
but typeof params.infer didn't bring the correct type, instead it looks like:
tokenManager: {
refreshToken: Promise<TokenInfo>;
readonly isTokenValid: boolean;
readonly token: string | undefined;
};
tokenManager: {
refreshToken: Promise<TokenInfo>;
readonly isTokenValid: boolean;
readonly token: string | undefined;
};
i.e. like some properties
74 replies
Aarktype
Created by OnkelTem on 10/11/2023 in #questions
Utility to make Partials?
Is there a way to get a type that is Partial<> from another type?
2 replies
Aarktype
Created by OnkelTem on 10/11/2023 in #questions
default values - how to define them?
I only found an issue by David that it's gonna be implemented, but I cannot find any examples.
6 replies
Aarktype
Created by OnkelTem on 10/11/2023 in #questions
Using existing enum/const to build a type
Hi folks. I'm very new to arktype so maybe I'm asking something very simple. I have a pseudo enum in a third-party module I import. This const is defined as:
export declare const VoiceId: {
readonly Aditi: "Aditi";
readonly Adriano: "Adriano";
readonly Amy: "Amy";
// ...
export declare const VoiceId: {
readonly Aditi: "Aditi";
readonly Adriano: "Adriano";
readonly Amy: "Amy";
// ...
How can I build an ark type from it?
7 replies
Aarktype
Created by OnkelTem on 10/11/2023 in #questions
How to import `arktype` into a typescript project?
I do it like this:
import { type } from 'arktype';
import { type } from 'arktype';
However, I get an error:
The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("arktype")' call instead.
To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '....../package.json'.ts(1479)
The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("arktype")' call instead.
To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '....../package.json'.ts(1479)
I tried to specify path to cjs version, but it didn't work:
import { type } from 'arktype/cjs'; // Cannot find module 'arktype/cjs' or its corresponding type declarations.ts(2307)
import { type } from 'arktype/cjs/main'; // Cannot find module 'arktype/cjs/main' or its corresponding type declarations.ts(2307)
import { type } from 'arktype/cjs'; // Cannot find module 'arktype/cjs' or its corresponding type declarations.ts(2307)
import { type } from 'arktype/cjs/main'; // Cannot find module 'arktype/cjs/main' or its corresponding type declarations.ts(2307)
How to get it imported?
33 replies