Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Getting started" steps for Runtime Types isn't working #581

Closed
micalevisk opened this issue Jun 22, 2024 · 2 comments
Closed

"Getting started" steps for Runtime Types isn't working #581

micalevisk opened this issue Jun 22, 2024 · 2 comments

Comments

@micalevisk
Copy link

After following the steps at https://deepkit.io/documentation/runtime-types/getting-started (everything before the Type compiler section) I'm seeing this error:

return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
app.ts:8:25 - error TS2693: 'User' only refers to a type, but is being used as a value here.

8 const user = cast<User>(User, {
                          ~~~~
app.ts:9:5 - error TS2353: Object literal may only specify known properties, and 'username' does not exist in type 'SerializationOptions'.

9     username: 'Peter',
      ~~~~~~~~
app.ts:14:41 - error TS2693: 'User' only refers to a type, but is being used as a value here.

14 const reflection = ReflectionClass.from(User);
                                           ~~~~

The repro: https://gitlab.com/micalevisk/deepkit-runtime-type-starter-issue

Steps to reproduce:

git clone https://gitlab.com/micalevisk/deepkit-runtime-type-starter-issue.git
cd deepkit-runtime-type-starter-issue
npm i
./node_modules/.bin/ts-node app.ts

running node_modules/.bin/deepkit-type-install didn't fix it neither.

@marcus-sa
Copy link
Contributor

marcus-sa commented Jun 23, 2024

You're trying to use a type as a value.
User is an interface not a class.

The correct code would be

import { cast, MinLength, ReflectionClass } from '@deepkit/type';

interface User {
    username: string & MinLength<3>;
    birthDate?: Date;
}

const user = cast<User>({
    username: 'Peter',
    birthDate: '2010-10-10T00:00:00Z'
});
console.log(user);

const reflection = ReflectionClass.from<User>();
console.log(reflection.getProperty('username').type);

@micalevisk
Copy link
Author

ty

#559 will fix that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants