v0.13.7
errors and warnings / types

errors and warnings / types / E2015

E2015 error

Type assertion between incomparable types

area
types (x2xxx)
fails the build
yes
in plain Lua files
reported as W2015

A type assertion (expr :: T) between types that can't be the same value: neither is assignable to the other, and they aren't both tables. An assertion can narrow or widen a type, not turn a number into a string. Fix the type, or, if you really know better, go through any: expr :: any :: T.

Example

× failswowlua
local n = 5local s = n :: stringprint(s)
✓ compileswowlua
local n: number | string = "five"local s = n :: stringprint(s)

The compiler reports it like this:

error[E2015]: cannot assert `number` as `string`
  ┌─ src/main.wowlua:2:11
  │
2 │ local s = n :: string
  │           ^^^^^^^^^^^ here
  │
  = help: to force the type, write `:: any :: string`
codemessage
E2001Type mismatch: S is not assignable to T

Offline

terminal
$ wowlua explain E2015
E2015 (error): Type assertion between incomparable types

source on GitHub ↗