0

I have a file called mock-values.ts that just has:

export const TIMES: Time[] = [
  { i: '8:00', v: '8' }, { i: '8:30', v: '8:30' },
  { i: '9:00', v: '9' }, { i: '9:30', v: '9:30' },
  { i: '10:00', v: '10' }, { i: '10:30', v: '10:30' },
  { i: '11:00', v: '11' }
];
export const MINUTES: Minute[] = [
  { half_hour: '30' },
  { half_hour: '60' },
  { half_hour: '90' }
];

When I run ng serve I am met with this error message ERROR in src/app/meeting-form/mock-values.ts(1,21): error TS2304: Cannot find name 'Time'. src/app/meeting-form/mock-values.ts(13,23): error TS2304: Cannot find name 'Minute'.

And here is my import in my form.component.ts

import { TIMES, MINUTES } from './mock-values';
  times = TIMES;
  minutes = MINUTES;

After about a minute it compiles successfully because it eventually finds it. Is there any way to tell Angular to chill out or make the process easier for the compiler?

4
  • Where are Time and Minute defined? Commented Dec 11, 2018 at 18:25
  • what are Time and Minute in the above code. Are they classes or interfaces that you have created? Commented Dec 11, 2018 at 18:28
  • In my form.component it looks like this times = TIMES; minutes = MINUTES; Commented Dec 11, 2018 at 18:35
  • You have to import Time and Minute on order to use them as a types Commented Dec 11, 2018 at 19:15

1 Answer 1

1

Looks like Time and Minute are not pre-defined types. Please try changing the code as below:

export const TIMES = [
  { i: '8:00', v: '8' }, { i: '8:30', v: '8:30' },
  { i: '9:00', v: '9' }, { i: '9:30', v: '9:30' },
  { i: '10:00', v: '10' }, { i: '10:30', v: '10:30' },
  { i: '11:00', v: '11' }
];
export const MINUTES = [
  { half_hour: '30' },
  { half_hour: '60' },
  { half_hour: '90' }
];
Sign up to request clarification or add additional context in comments.

2 Comments

I don't understand why I have to import anything. It's only a data file so the code is cleaner. There is no import path only an export. I tried this solution but all it does is shift the problem to the import rather than the object.
It could export as plain objects and then cast them at the import side. I don't see why though, if you want to use it in more than one place you would have to do this every time. It's much easier to import the types in the data file and type it there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.