errors and warnings / types / E2001
E2001 error
Type mismatch: S is not assignable to T
- area
- types (x2xxx)
- fails the build
- yes
- in plain Lua files
- reported as W2001
A value's type doesn't fit where it is used: an argument, an assignment to a local or field, or a return value. The same code covers an operator used on a type it doesn't take, such as comparing a number with a string or doing arithmetic on a boolean. Change the value, or widen the annotation if the value is right.
A local without an annotation takes the type of the value it is declared with
(local test = 3 is a number), and later assignments must fit that type as
if it were written out. To hold other values too, annotate it
(local test: number | string = 3). A local declared without a value, or with
nil, holds whatever is assigned to it.
In a plain Lua file (no wowlua syntax, no --!strict) the checker reports the
warning with the same number, W2001, so existing code keeps building.
Example
local count: number = "3"print(count)local count: number = 3print(count)local test = 3test = "hello world"print(`test: {test}`)local test: number | string = 3test = "hello world"print(`test: {test}`)The compiler reports it like this:
error[E2001]: `"3"` is not assignable to `number` ┌─ src/main.wowlua:1:7 │ 1 │ local count: number = "3" │ ^^^^^ here
Related codes
| code | message |
|---|---|
| W2001 | Type mismatch: S is not assignable to T (in a plain Lua file) |
| E2005 | Value may be nil (strict mode) |
Offline
$ wowlua explain E2001 E2001 (error): Type mismatch: S is not assignable to T