intros.
elim item_trunc with (1 := H); intros.
apply thinning_n with x; auto with arith pts.
apply wf_definition with (1 := H); trivial with arith pts.
Qed.

Theorem typ_sub :
forall (g : env) (x : term) (d : decl),
typ g x (typ_of_decl d) ->
forall (e : env) (u U : term),
typ e u U ->
forall (f : env) (n : nat),
sub_in_env g d x n e f ->
wf f -> typ f (subst_rec x u n) (subst_rec x U n).