Skip to content

bug: Type 'void' is not assignable to type 'void' although not returning the expression #1960

Closed
@trusktr

Description

@trusktr

input:

let s: string | null = null

declare function log(s: string): void

/** Calculates the n-th Fibonacci number. */
export function fib(n: i32): i32 {
  s != null ? log("not null") : log("null") // <--------------- error
  return 123
}

error:

;; INFO asc module.ts --textFile module.wat --binaryFile module.wasm -O3 --runtime stub
;; ERROR TS2322: Type 'void' is not assignable to type 'void'.
;; 
;;    s != null ? log("not null") : log("null")
;;                                  ~~~~~~~~~~~
;;  in module.ts(7,33)
;; 
;; ERROR TS2355: A function whose declared type is not 'void' must return a value.
;; 
;;  export function fib(n: i32): i32 {
;;                               ~~~
;;  in module.ts(6,30)
(module
 ;; FAILURE 2 compile error(s)
)

playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions