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

question: the forbidUnknownValues option has no effect #896

Closed
MickL opened this issue Feb 8, 2021 · 3 comments
Closed

question: the forbidUnknownValues option has no effect #896

MickL opened this issue Feb 8, 2021 · 3 comments
Labels
type: question Questions about the usage of the library.

Comments

@MickL
Copy link

MickL commented Feb 8, 2021

Description

import { IsString, validateSync } from 'class-validator';
import { plainToClass } from 'class-transformer';

class MyClass {
    @IsString()
    id: string;
}

const myObj = {
    id: '123',
    hello: 'world',
};

const validated = plainToClass(MyClass, myObj);

const errors = validateSync(validated, {
    forbidUnknownValues:   true,
});

console.log(errors)

Expected behavior

Should throw an error that hello is not allowed.

Actual behavior

Error-array is empty

@MickL MickL added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Feb 8, 2021
@MickL MickL changed the title forbidUnknownValues does not have any effect fix: forbidUnknownValues does not have any effect Feb 8, 2021
@pskopnik
Copy link

You're looking for the whitelist-related options, see Whitelisting:

const errors = validateSync(classedValue, { whitelist: true, forbidNonWhitelisted: true });

forbidUnknownValues serves a different purpose, although the name has led to much confusion #314 #305.

@NoNameProvided NoNameProvided added type: question Questions about the usage of the library. and removed type: fix Issues describing a broken feature. status: needs triage Issues which needs to be reproduced to be verified report. labels Dec 9, 2022
@NoNameProvided NoNameProvided changed the title fix: forbidUnknownValues does not have any effect question: the forbidUnknownValues option has no effect Dec 9, 2022
@NoNameProvided
Copy link
Member

As answered by @pskopnik, the forbidUnknownValues option serves a different purpose.

@github-actions
Copy link

github-actions bot commented Jan 9, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: question Questions about the usage of the library.
Development

Successfully merging a pull request may close this issue.

3 participants