TypeScript 3 form validation object
up vote
1
down vote
favorite
Please, correct me with anything that I say in here (The actual question is below the code).
I've been quickly prototyping a project (ASP.NET Core 2.1) and haven't found the need to structure it with Webpack/Parcel/Rollup/Browserify as it's done with simple JavaScript validations per views (I do minify the files with Gulp).
Since I'm not enclosing my files into modules, they're all open to the global scope (bad idea, right?). Therefore, I've decided to "namespace" them by running everything inside a JavaScript variable.
The code that I have looks like this:
const formValidation = {
submitBtn : null as unknown as HTMLButtonElement,
errors: null as unknown as string,
errorsDiv: null as unknown as HTMLDivElement,
gradeSections: null as unknown as HTMLDivElement,
form: null as unknown as HTMLFormElement,
mapDOM() {
this.submitBtn = document.getElementById('js-btn-submit') as HTMLButtonElement;
this.errorsDiv = document.getElementById('js-errors') as HTMLDivElement;
this.gradeSections = document.getElementById('js-grade-sections') as HTMLDivElement;
this.form = document.getElementById('js-submit-form') as HTMLFormElement;
this.mapEventListenersFormValidation();
},
mapEventListenersFormValidation() {
this.submitBtn.addEventListener('click', this.submit.bind(this));
},
submit(evt: Event) {
console.log(evt);
evt.preventDefault();
this.resetForms();
if (!this.checkIfSubmitIsValid()) {
this.showErrors();
return;
}
this.form.submit();
},
checkIfSubmitIsValid() {
this.errors = ;
const subjectSelected = this.isSubjectSelected();
const sectionsSelected = this.areSectionsSelected();
if (!subjectSelected) {
selectSubjectDropdown.classList.add('is-invalid');
this.errors.push('Debe de seleccionar por lo menos una materia');
}
if (!sectionsSelected) {
this.gradeSections.classList.add('form-error');
this.errors.push('Debe de seleccionar al menos una sección');
}
return subjectSelected && sectionsSelected;
},
isSubjectSelected() {
return selectSubjectDropdown.selectedIndex !== 0;
},
areSectionsSelected() {
return selectedSectionCounter > 0;
},
showErrors() {
if (!this.errorsDiv || !this.errorsDiv.parentElement) {
return;
}
this.errorsDiv.parentElement.removeAttribute('hidden');
this.errorsDiv.innerHTML = '';
this.errors.forEach((error) => {
const li = document.createElement('li');
li.innerHTML = error;
this.errorsDiv.appendChild(li);
});
},
resetForms() {
selectSubjectDropdown.classList.remove('is-invalid');
this.gradeSections.classList.remove('form-error');
},
};
DOMReady(formValidation.mapDOM.bind(formValidation));
Check the submitBtn, errors, and errorsDiv properties. AFAIK, JavaScript doesn't have a way to declare an "empty" property. Therefore something sane would be to assign it either undefined
or null
.
As I want to have it statically defined (through TypeScript), I want to assign a type to those properties. The problem is that I just can't assign a non-nullable type to a null.
As I'm trying to avoid non-implicit any's in the scripts, the compiler suggested me to use unknown
.
The question is, whether it's ok for me to use the unknown
type from TypeScript to cast a null to an unknown so it can let me cast it to the type that I'm going after.
Edit Ended up adding the whole document into it. I was working with that function, so it's different now.
validation dom typescript null type-safety
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
up vote
1
down vote
favorite
Please, correct me with anything that I say in here (The actual question is below the code).
I've been quickly prototyping a project (ASP.NET Core 2.1) and haven't found the need to structure it with Webpack/Parcel/Rollup/Browserify as it's done with simple JavaScript validations per views (I do minify the files with Gulp).
Since I'm not enclosing my files into modules, they're all open to the global scope (bad idea, right?). Therefore, I've decided to "namespace" them by running everything inside a JavaScript variable.
The code that I have looks like this:
const formValidation = {
submitBtn : null as unknown as HTMLButtonElement,
errors: null as unknown as string,
errorsDiv: null as unknown as HTMLDivElement,
gradeSections: null as unknown as HTMLDivElement,
form: null as unknown as HTMLFormElement,
mapDOM() {
this.submitBtn = document.getElementById('js-btn-submit') as HTMLButtonElement;
this.errorsDiv = document.getElementById('js-errors') as HTMLDivElement;
this.gradeSections = document.getElementById('js-grade-sections') as HTMLDivElement;
this.form = document.getElementById('js-submit-form') as HTMLFormElement;
this.mapEventListenersFormValidation();
},
mapEventListenersFormValidation() {
this.submitBtn.addEventListener('click', this.submit.bind(this));
},
submit(evt: Event) {
console.log(evt);
evt.preventDefault();
this.resetForms();
if (!this.checkIfSubmitIsValid()) {
this.showErrors();
return;
}
this.form.submit();
},
checkIfSubmitIsValid() {
this.errors = ;
const subjectSelected = this.isSubjectSelected();
const sectionsSelected = this.areSectionsSelected();
if (!subjectSelected) {
selectSubjectDropdown.classList.add('is-invalid');
this.errors.push('Debe de seleccionar por lo menos una materia');
}
if (!sectionsSelected) {
this.gradeSections.classList.add('form-error');
this.errors.push('Debe de seleccionar al menos una sección');
}
return subjectSelected && sectionsSelected;
},
isSubjectSelected() {
return selectSubjectDropdown.selectedIndex !== 0;
},
areSectionsSelected() {
return selectedSectionCounter > 0;
},
showErrors() {
if (!this.errorsDiv || !this.errorsDiv.parentElement) {
return;
}
this.errorsDiv.parentElement.removeAttribute('hidden');
this.errorsDiv.innerHTML = '';
this.errors.forEach((error) => {
const li = document.createElement('li');
li.innerHTML = error;
this.errorsDiv.appendChild(li);
});
},
resetForms() {
selectSubjectDropdown.classList.remove('is-invalid');
this.gradeSections.classList.remove('form-error');
},
};
DOMReady(formValidation.mapDOM.bind(formValidation));
Check the submitBtn, errors, and errorsDiv properties. AFAIK, JavaScript doesn't have a way to declare an "empty" property. Therefore something sane would be to assign it either undefined
or null
.
As I want to have it statically defined (through TypeScript), I want to assign a type to those properties. The problem is that I just can't assign a non-nullable type to a null.
As I'm trying to avoid non-implicit any's in the scripts, the compiler suggested me to use unknown
.
The question is, whether it's ok for me to use the unknown
type from TypeScript to cast a null to an unknown so it can let me cast it to the type that I'm going after.
Edit Ended up adding the whole document into it. I was working with that function, so it's different now.
validation dom typescript null type-safety
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
The code to be reviewed looks sketchy or incomplete: where arecheckIfSubmitIsValid()
andshowErrors()
defined?
– 200_success
Nov 1 at 14:14
@200_success: Oh they're not needed for what I'm looking for. It's the second and third line of the code snippet above.
– Jose A
Nov 1 at 23:44
Maybe they're not needed for what you are looking for, but context is still important for reviewers.
– 200_success
Nov 1 at 23:55
@200_success: Got it! I'll update it asap! Sorry
– Jose A
Nov 2 at 0:07
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Please, correct me with anything that I say in here (The actual question is below the code).
I've been quickly prototyping a project (ASP.NET Core 2.1) and haven't found the need to structure it with Webpack/Parcel/Rollup/Browserify as it's done with simple JavaScript validations per views (I do minify the files with Gulp).
Since I'm not enclosing my files into modules, they're all open to the global scope (bad idea, right?). Therefore, I've decided to "namespace" them by running everything inside a JavaScript variable.
The code that I have looks like this:
const formValidation = {
submitBtn : null as unknown as HTMLButtonElement,
errors: null as unknown as string,
errorsDiv: null as unknown as HTMLDivElement,
gradeSections: null as unknown as HTMLDivElement,
form: null as unknown as HTMLFormElement,
mapDOM() {
this.submitBtn = document.getElementById('js-btn-submit') as HTMLButtonElement;
this.errorsDiv = document.getElementById('js-errors') as HTMLDivElement;
this.gradeSections = document.getElementById('js-grade-sections') as HTMLDivElement;
this.form = document.getElementById('js-submit-form') as HTMLFormElement;
this.mapEventListenersFormValidation();
},
mapEventListenersFormValidation() {
this.submitBtn.addEventListener('click', this.submit.bind(this));
},
submit(evt: Event) {
console.log(evt);
evt.preventDefault();
this.resetForms();
if (!this.checkIfSubmitIsValid()) {
this.showErrors();
return;
}
this.form.submit();
},
checkIfSubmitIsValid() {
this.errors = ;
const subjectSelected = this.isSubjectSelected();
const sectionsSelected = this.areSectionsSelected();
if (!subjectSelected) {
selectSubjectDropdown.classList.add('is-invalid');
this.errors.push('Debe de seleccionar por lo menos una materia');
}
if (!sectionsSelected) {
this.gradeSections.classList.add('form-error');
this.errors.push('Debe de seleccionar al menos una sección');
}
return subjectSelected && sectionsSelected;
},
isSubjectSelected() {
return selectSubjectDropdown.selectedIndex !== 0;
},
areSectionsSelected() {
return selectedSectionCounter > 0;
},
showErrors() {
if (!this.errorsDiv || !this.errorsDiv.parentElement) {
return;
}
this.errorsDiv.parentElement.removeAttribute('hidden');
this.errorsDiv.innerHTML = '';
this.errors.forEach((error) => {
const li = document.createElement('li');
li.innerHTML = error;
this.errorsDiv.appendChild(li);
});
},
resetForms() {
selectSubjectDropdown.classList.remove('is-invalid');
this.gradeSections.classList.remove('form-error');
},
};
DOMReady(formValidation.mapDOM.bind(formValidation));
Check the submitBtn, errors, and errorsDiv properties. AFAIK, JavaScript doesn't have a way to declare an "empty" property. Therefore something sane would be to assign it either undefined
or null
.
As I want to have it statically defined (through TypeScript), I want to assign a type to those properties. The problem is that I just can't assign a non-nullable type to a null.
As I'm trying to avoid non-implicit any's in the scripts, the compiler suggested me to use unknown
.
The question is, whether it's ok for me to use the unknown
type from TypeScript to cast a null to an unknown so it can let me cast it to the type that I'm going after.
Edit Ended up adding the whole document into it. I was working with that function, so it's different now.
validation dom typescript null type-safety
Please, correct me with anything that I say in here (The actual question is below the code).
I've been quickly prototyping a project (ASP.NET Core 2.1) and haven't found the need to structure it with Webpack/Parcel/Rollup/Browserify as it's done with simple JavaScript validations per views (I do minify the files with Gulp).
Since I'm not enclosing my files into modules, they're all open to the global scope (bad idea, right?). Therefore, I've decided to "namespace" them by running everything inside a JavaScript variable.
The code that I have looks like this:
const formValidation = {
submitBtn : null as unknown as HTMLButtonElement,
errors: null as unknown as string,
errorsDiv: null as unknown as HTMLDivElement,
gradeSections: null as unknown as HTMLDivElement,
form: null as unknown as HTMLFormElement,
mapDOM() {
this.submitBtn = document.getElementById('js-btn-submit') as HTMLButtonElement;
this.errorsDiv = document.getElementById('js-errors') as HTMLDivElement;
this.gradeSections = document.getElementById('js-grade-sections') as HTMLDivElement;
this.form = document.getElementById('js-submit-form') as HTMLFormElement;
this.mapEventListenersFormValidation();
},
mapEventListenersFormValidation() {
this.submitBtn.addEventListener('click', this.submit.bind(this));
},
submit(evt: Event) {
console.log(evt);
evt.preventDefault();
this.resetForms();
if (!this.checkIfSubmitIsValid()) {
this.showErrors();
return;
}
this.form.submit();
},
checkIfSubmitIsValid() {
this.errors = ;
const subjectSelected = this.isSubjectSelected();
const sectionsSelected = this.areSectionsSelected();
if (!subjectSelected) {
selectSubjectDropdown.classList.add('is-invalid');
this.errors.push('Debe de seleccionar por lo menos una materia');
}
if (!sectionsSelected) {
this.gradeSections.classList.add('form-error');
this.errors.push('Debe de seleccionar al menos una sección');
}
return subjectSelected && sectionsSelected;
},
isSubjectSelected() {
return selectSubjectDropdown.selectedIndex !== 0;
},
areSectionsSelected() {
return selectedSectionCounter > 0;
},
showErrors() {
if (!this.errorsDiv || !this.errorsDiv.parentElement) {
return;
}
this.errorsDiv.parentElement.removeAttribute('hidden');
this.errorsDiv.innerHTML = '';
this.errors.forEach((error) => {
const li = document.createElement('li');
li.innerHTML = error;
this.errorsDiv.appendChild(li);
});
},
resetForms() {
selectSubjectDropdown.classList.remove('is-invalid');
this.gradeSections.classList.remove('form-error');
},
};
DOMReady(formValidation.mapDOM.bind(formValidation));
Check the submitBtn, errors, and errorsDiv properties. AFAIK, JavaScript doesn't have a way to declare an "empty" property. Therefore something sane would be to assign it either undefined
or null
.
As I want to have it statically defined (through TypeScript), I want to assign a type to those properties. The problem is that I just can't assign a non-nullable type to a null.
As I'm trying to avoid non-implicit any's in the scripts, the compiler suggested me to use unknown
.
The question is, whether it's ok for me to use the unknown
type from TypeScript to cast a null to an unknown so it can let me cast it to the type that I'm going after.
Edit Ended up adding the whole document into it. I was working with that function, so it's different now.
validation dom typescript null type-safety
validation dom typescript null type-safety
edited Nov 2 at 0:08
asked Oct 31 at 20:20
Jose A
1436
1436
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
The code to be reviewed looks sketchy or incomplete: where arecheckIfSubmitIsValid()
andshowErrors()
defined?
– 200_success
Nov 1 at 14:14
@200_success: Oh they're not needed for what I'm looking for. It's the second and third line of the code snippet above.
– Jose A
Nov 1 at 23:44
Maybe they're not needed for what you are looking for, but context is still important for reviewers.
– 200_success
Nov 1 at 23:55
@200_success: Got it! I'll update it asap! Sorry
– Jose A
Nov 2 at 0:07
add a comment |
The code to be reviewed looks sketchy or incomplete: where arecheckIfSubmitIsValid()
andshowErrors()
defined?
– 200_success
Nov 1 at 14:14
@200_success: Oh they're not needed for what I'm looking for. It's the second and third line of the code snippet above.
– Jose A
Nov 1 at 23:44
Maybe they're not needed for what you are looking for, but context is still important for reviewers.
– 200_success
Nov 1 at 23:55
@200_success: Got it! I'll update it asap! Sorry
– Jose A
Nov 2 at 0:07
The code to be reviewed looks sketchy or incomplete: where are
checkIfSubmitIsValid()
and showErrors()
defined?– 200_success
Nov 1 at 14:14
The code to be reviewed looks sketchy or incomplete: where are
checkIfSubmitIsValid()
and showErrors()
defined?– 200_success
Nov 1 at 14:14
@200_success: Oh they're not needed for what I'm looking for. It's the second and third line of the code snippet above.
– Jose A
Nov 1 at 23:44
@200_success: Oh they're not needed for what I'm looking for. It's the second and third line of the code snippet above.
– Jose A
Nov 1 at 23:44
Maybe they're not needed for what you are looking for, but context is still important for reviewers.
– 200_success
Nov 1 at 23:55
Maybe they're not needed for what you are looking for, but context is still important for reviewers.
– 200_success
Nov 1 at 23:55
@200_success: Got it! I'll update it asap! Sorry
– Jose A
Nov 2 at 0:07
@200_success: Got it! I'll update it asap! Sorry
– Jose A
Nov 2 at 0:07
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The compiler can't know beforehand if document.getElementById('js-btn-submit')
wil return anything. That is why you cannot assign the result directly to a type.
One solution is to tell the compiler that you are certain that the HTML element exists, using !
let button = document.getElementById("button")! as HTMLButtonElement
If you are NOT certain that the button exists in the HTML document, you can use the suggestion given by VS Code:
If you hover the mouse over document.getElementById
you can see that the returned type is null | HTMLElement
I've rewritten your object as a class, because in object notation the colon is used to pass the value, not the type: const obj = {a:3}
class FormValidation {
submitBtn: null | HTMLButtonElement
mapDOM() {
this.submitBtn = document.getElementById('js-btn-submit') as HTMLButtonElement;
}
}
const f = new FormValidation()
f.mapDOM()
Thanks Kokodoko, the only thing is that the compiler is now complaining with "null" by saying that "Object is possibly null", and that "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type". I've also checked thatnull as unkown | HTMLFormElement
works as well!
– Jose A
Nov 1 at 23:47
I see, this is because the colon:
in object notation is used to pass the value, instead of the type!obj = {a:3}
. So you can't define the type in this way. In my update I have rewritten the object as a class so you can define the type.
– Kokodoko
Nov 2 at 8:35
If it's a class it then does make sense! You even gave me an idea! To define the object's property at the object level and not at the property level!! Thanks :)
– Jose A
Nov 2 at 11:07
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The compiler can't know beforehand if document.getElementById('js-btn-submit')
wil return anything. That is why you cannot assign the result directly to a type.
One solution is to tell the compiler that you are certain that the HTML element exists, using !
let button = document.getElementById("button")! as HTMLButtonElement
If you are NOT certain that the button exists in the HTML document, you can use the suggestion given by VS Code:
If you hover the mouse over document.getElementById
you can see that the returned type is null | HTMLElement
I've rewritten your object as a class, because in object notation the colon is used to pass the value, not the type: const obj = {a:3}
class FormValidation {
submitBtn: null | HTMLButtonElement
mapDOM() {
this.submitBtn = document.getElementById('js-btn-submit') as HTMLButtonElement;
}
}
const f = new FormValidation()
f.mapDOM()
Thanks Kokodoko, the only thing is that the compiler is now complaining with "null" by saying that "Object is possibly null", and that "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type". I've also checked thatnull as unkown | HTMLFormElement
works as well!
– Jose A
Nov 1 at 23:47
I see, this is because the colon:
in object notation is used to pass the value, instead of the type!obj = {a:3}
. So you can't define the type in this way. In my update I have rewritten the object as a class so you can define the type.
– Kokodoko
Nov 2 at 8:35
If it's a class it then does make sense! You even gave me an idea! To define the object's property at the object level and not at the property level!! Thanks :)
– Jose A
Nov 2 at 11:07
add a comment |
up vote
0
down vote
The compiler can't know beforehand if document.getElementById('js-btn-submit')
wil return anything. That is why you cannot assign the result directly to a type.
One solution is to tell the compiler that you are certain that the HTML element exists, using !
let button = document.getElementById("button")! as HTMLButtonElement
If you are NOT certain that the button exists in the HTML document, you can use the suggestion given by VS Code:
If you hover the mouse over document.getElementById
you can see that the returned type is null | HTMLElement
I've rewritten your object as a class, because in object notation the colon is used to pass the value, not the type: const obj = {a:3}
class FormValidation {
submitBtn: null | HTMLButtonElement
mapDOM() {
this.submitBtn = document.getElementById('js-btn-submit') as HTMLButtonElement;
}
}
const f = new FormValidation()
f.mapDOM()
Thanks Kokodoko, the only thing is that the compiler is now complaining with "null" by saying that "Object is possibly null", and that "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type". I've also checked thatnull as unkown | HTMLFormElement
works as well!
– Jose A
Nov 1 at 23:47
I see, this is because the colon:
in object notation is used to pass the value, instead of the type!obj = {a:3}
. So you can't define the type in this way. In my update I have rewritten the object as a class so you can define the type.
– Kokodoko
Nov 2 at 8:35
If it's a class it then does make sense! You even gave me an idea! To define the object's property at the object level and not at the property level!! Thanks :)
– Jose A
Nov 2 at 11:07
add a comment |
up vote
0
down vote
up vote
0
down vote
The compiler can't know beforehand if document.getElementById('js-btn-submit')
wil return anything. That is why you cannot assign the result directly to a type.
One solution is to tell the compiler that you are certain that the HTML element exists, using !
let button = document.getElementById("button")! as HTMLButtonElement
If you are NOT certain that the button exists in the HTML document, you can use the suggestion given by VS Code:
If you hover the mouse over document.getElementById
you can see that the returned type is null | HTMLElement
I've rewritten your object as a class, because in object notation the colon is used to pass the value, not the type: const obj = {a:3}
class FormValidation {
submitBtn: null | HTMLButtonElement
mapDOM() {
this.submitBtn = document.getElementById('js-btn-submit') as HTMLButtonElement;
}
}
const f = new FormValidation()
f.mapDOM()
The compiler can't know beforehand if document.getElementById('js-btn-submit')
wil return anything. That is why you cannot assign the result directly to a type.
One solution is to tell the compiler that you are certain that the HTML element exists, using !
let button = document.getElementById("button")! as HTMLButtonElement
If you are NOT certain that the button exists in the HTML document, you can use the suggestion given by VS Code:
If you hover the mouse over document.getElementById
you can see that the returned type is null | HTMLElement
I've rewritten your object as a class, because in object notation the colon is used to pass the value, not the type: const obj = {a:3}
class FormValidation {
submitBtn: null | HTMLButtonElement
mapDOM() {
this.submitBtn = document.getElementById('js-btn-submit') as HTMLButtonElement;
}
}
const f = new FormValidation()
f.mapDOM()
edited Nov 2 at 8:40
answered Nov 1 at 11:37
Kokodoko
1967
1967
Thanks Kokodoko, the only thing is that the compiler is now complaining with "null" by saying that "Object is possibly null", and that "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type". I've also checked thatnull as unkown | HTMLFormElement
works as well!
– Jose A
Nov 1 at 23:47
I see, this is because the colon:
in object notation is used to pass the value, instead of the type!obj = {a:3}
. So you can't define the type in this way. In my update I have rewritten the object as a class so you can define the type.
– Kokodoko
Nov 2 at 8:35
If it's a class it then does make sense! You even gave me an idea! To define the object's property at the object level and not at the property level!! Thanks :)
– Jose A
Nov 2 at 11:07
add a comment |
Thanks Kokodoko, the only thing is that the compiler is now complaining with "null" by saying that "Object is possibly null", and that "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type". I've also checked thatnull as unkown | HTMLFormElement
works as well!
– Jose A
Nov 1 at 23:47
I see, this is because the colon:
in object notation is used to pass the value, instead of the type!obj = {a:3}
. So you can't define the type in this way. In my update I have rewritten the object as a class so you can define the type.
– Kokodoko
Nov 2 at 8:35
If it's a class it then does make sense! You even gave me an idea! To define the object's property at the object level and not at the property level!! Thanks :)
– Jose A
Nov 2 at 11:07
Thanks Kokodoko, the only thing is that the compiler is now complaining with "null" by saying that "Object is possibly null", and that "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type". I've also checked that
null as unkown | HTMLFormElement
works as well!– Jose A
Nov 1 at 23:47
Thanks Kokodoko, the only thing is that the compiler is now complaining with "null" by saying that "Object is possibly null", and that "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type". I've also checked that
null as unkown | HTMLFormElement
works as well!– Jose A
Nov 1 at 23:47
I see, this is because the colon
:
in object notation is used to pass the value, instead of the type! obj = {a:3}
. So you can't define the type in this way. In my update I have rewritten the object as a class so you can define the type.– Kokodoko
Nov 2 at 8:35
I see, this is because the colon
:
in object notation is used to pass the value, instead of the type! obj = {a:3}
. So you can't define the type in this way. In my update I have rewritten the object as a class so you can define the type.– Kokodoko
Nov 2 at 8:35
If it's a class it then does make sense! You even gave me an idea! To define the object's property at the object level and not at the property level!! Thanks :)
– Jose A
Nov 2 at 11:07
If it's a class it then does make sense! You even gave me an idea! To define the object's property at the object level and not at the property level!! Thanks :)
– Jose A
Nov 2 at 11:07
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f206689%2ftypescript-3-form-validation-object%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The code to be reviewed looks sketchy or incomplete: where are
checkIfSubmitIsValid()
andshowErrors()
defined?– 200_success
Nov 1 at 14:14
@200_success: Oh they're not needed for what I'm looking for. It's the second and third line of the code snippet above.
– Jose A
Nov 1 at 23:44
Maybe they're not needed for what you are looking for, but context is still important for reviewers.
– 200_success
Nov 1 at 23:55
@200_success: Got it! I'll update it asap! Sorry
– Jose A
Nov 2 at 0:07