Say that I'm building an app that is a car app, and I want to define what a car looks like using a typescript class. Where should I put that file in relation to my car component? Should I have a whole new folder that houses all of my class files? Should the class file be in with my component? Is there a standard? I would think having them in a folder outside of the component would make most sense so that they are more reusable. Thoughts?
Asked
Active
Viewed 1,230 times
1 Answers
2
It's up to you. Whatever puts your OCD at ease.
However, here's what I would do:
- Create an
interface
orclass
that represents a Car - If the
Car
model is only used within the Car Component, create a folder calledmodels
within your Car Component. However, if theCar
model is used in many different places, I would put in /shared/models/car.ts. This is helpful when you start to get a bunch of classes and you can have a pattern of "local classes" and "shared classes"
Example of what your Car
might look like:
export interface Car {
make: string;
model: string;
year: number;
color: string;
}
Read through this SOF thread if you have any confusion on class
vs interface

mwilson
- 12,295
- 7
- 55
- 95
-
2Haha, thanks, I was just diagnosed with OCD the other day actually so this is beyond funny. – testerson testing Mar 25 '20 at 17:25