I am learning type assertion concept in typescript. After Reading tutorial offical documentation, older version and some others, I have been confused about how typescript evaluates type assertions as valid.
the following example will make my problem more clear:
I have some type in the code:
type typA = {
name: string;
};
type typB = {
name: string;
age: number;
};
type typC = {
isGraduated: boolean;
};
type typD = {
address: string;
age: number;
};
type typEmpty = {};
then i created some variables that have the above types:
let a: typA = {
name: "John",
};
let b: typB = {
name: "Alex",
age: 10,
};
The problem happen when i run the code below:
a as typEmpty; // (1) Ok
b as typEmpty; // (2) Ok
a as typB; // (3) Ok
b as typA; // (4) Ok
b as typC; // (5) error: ts(2352) Conversion of type '...' to type '...' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
b as typD; // (6) error: ts(2352) Conversion of type '...' to type '...' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
1 as string // (7) error: ts(2352) Conversion of type '...' to type '...' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
b as never as typC; // (8) suprisingly, Ok
b as unknown as typC; // (9) suprisingly, Ok
b as any as typC; // (10) suprisingly, Ok
1 as never as string // (11) suprisingly, Ok
I have wonder that Why (8), (9), (10) and (11) are Ok while (5),(6), (7) make error?
I have searched a lot before pushing question in here, but i have not found reasonable answers yet.
Thanks for considering my stupid question.

never/unknown/anycompletely lack structural information), then asserting again with completely new information — so the compiler has nothing to compare against — the only option is for it to essentially conclude: "If you say so…🤷".