mirror of
https://github.com/swc-project/swc.git
synced 2024-12-27 15:42:51 +03:00
25 lines
384 B
TypeScript
25 lines
384 B
TypeScript
const keywordA = 'a';
|
|
const keywordB = 'b';
|
|
|
|
type A = { [keywordA]: number };
|
|
type B = { [keywordB]: string };
|
|
|
|
declare const c: A | B;
|
|
|
|
if ('a' in c) {
|
|
c; // narrowed to `A`
|
|
}
|
|
|
|
if (keywordA in c) {
|
|
c; // also narrowed to `A`
|
|
}
|
|
|
|
let stringB: string = 'b';
|
|
|
|
if ((stringB as 'b') in c) {
|
|
c; // narrowed to `B`
|
|
}
|
|
|
|
if ((stringB as ('a' | 'b')) in c) {
|
|
c; // not narrowed
|
|
} |