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

Compile error trying to use process.time() #2691

Closed
brian-hay opened this issue Apr 23, 2023 · 3 comments · Fixed by #2693
Closed

Compile error trying to use process.time() #2691

brian-hay opened this issue Apr 23, 2023 · 3 comments · Fixed by #2693
Labels

Comments

@brian-hay
Copy link

brian-hay commented Apr 23, 2023

Question

New to AS so it's likely me doing something wrong.

When I try to export a function using process.time() I receive a compile error:

import { process } from 'process';

export function start(): void {
  const time: i64 = process.time();
}
ERROR AS200: Conversion from type 'f64' to 'i64' requires an explicit cast.
    :
 32 │ return Date_binding.now();
    │        ~~~~~~~~~~~~~~~~~~
    └─ in ~lib/process.ts(32,12)
@brian-hay brian-hay changed the title Questions about time - Compile error trying to use process.time() Compile error trying to use process.time() Apr 23, 2023
@dcodeIO dcodeIO added bug and removed question labels Apr 23, 2023
@dcodeIO
Copy link
Member

dcodeIO commented Apr 23, 2023

You are doing everything right, this looks like a bug.

export function time(): i64 {
return Date_binding.now();
}

Should be

  export function time(): i64 {
    return <i64>Date_binding.now();
  }

because now returns an f64 (a number from JS).

@dcodeIO
Copy link
Member

dcodeIO commented Apr 23, 2023

Side note: I am not quite sure why process.time exists in the first place, though, given that Node doesn't have it and there is Date.now doing the same. Probably better to use Date.now instead.

@brian-hay
Copy link
Author

Thanks @dcodeIO for jumping on this so quick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants