Closed sebascomeau closed 3 years ago
@sebascomeau if you use the wrong property name elsewhere, does it cause a compile error? I'm wondering if type checking happens at all. Type checking should happen before the ts-nameof transformation so you should get a compile error.
Type checking doesn't seems to work at all. I just move some fields from interfaces and no errors.
@sebascomeau is this option set to true? https://nextjs.org/docs/api-reference/next.config.js/ignoring-typescript-errors
This option is not set to default to false.
I get error if I put the wrong type name in nameof
But if I type the wrong prop name then no error and it build.
But I get an error if the prop name is type Interface. Good Error
With wrong name of that prop no error...
Prop Correct
Prop name NOT Correct with no error
I think I just found the problem....
Index Types... it's the reason why I dont get any error.
@sebascomeau yes, that looks like the problem.
I need Index Types because I have a generic funtion to updated string type with field name.
const handleOnTextFieldChange: TextFieldOnChangeEvent & TextAreaFieldOnChangeEvent = ({ field, value }) => {
setFormDataState((prev) => {
const newObj = { ...prev.expressionOfInterest, [field]: value ?? undefined };
return { ...prev, expressionOfInterest: newObj };
});
};
You should add a note on that in the documentation.
@sebascomeau you may want to create a separate type that doesn't have the index type.
interface TypeWithOnlyProperties {
prop: string;
}
interface TypeWithEverything extends TypeWithOnlyProperties {
[key: string]: string | undefined;
}
nameof<TypeWithOnlyProperties>(o => o.otherProp); // error
Thanks for the tips. I will do that.
I using ts-nameof to reduce the number of petiential bug that string can cause when using class or interface prop names. It work great in general but if I type the wrong prop name then it compile without any errors. Am I doing someting wrong or it's something that you can't manage?
I tried both babel typescript and babel macros ways to compile and both do the same behavior, no error caught. I'm working on a new NextJs project.
node version: 14.16.0
tsconfig.json
packages.json