errors and warnings / types / E2014
E2014 error
Type argument does not satisfy its constraint
- area
- types (x2xxx)
- fails the build
- yes
- in plain Lua files
- reported as W2014
A type parameter declared with extends was given a type that doesn't
satisfy its constraint. Type arguments are inferred from the call, so this
usually means an argument of the wrong type: a list of strings where items
with a size are needed, or a key that isn't one of the table's fields for
K extends keyof T.
Example
local function largest<T extends { size: number }>(xs: T[]): T return xs[1]endprint(largest({ "a", "b" }))local function largest<T extends { size: number }>(xs: T[]): T return xs[1]endprint(largest({ { size = 1 } }))The compiler reports it like this:
error[E2014]: `string` does not satisfy the constraint `{ size: number }` of `T` ┌─ src/main.wowlua:4:7 │ 4 │ print(largest({ "a", "b" })) │ ^^^^^^^^^^^^^^^^^^^^^ here
Related codes
Offline
$ wowlua explain E2014 E2014 (error): Type argument does not satisfy its constraint