-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Union properties are broken #83
Comments
Hi, |
Check the issue #45 |
I'm similarly seeing some weirdness when using optional properties or unions. However I have import { getType } from "tst-reflect";
function printTypeProperties<TType>() {
const type = getType<TType>(); // <<== get type of type parameter TType
console.log(type.getProperties().map(prop => prop.name + ": " + prop.type.name + `, isOptional: ${prop.optional}` + `, isUnion: ${prop.type.isUnion()}` + `, type: ${prop.type}`).join("\n"));
}
interface SomeType {
foo: string;
bar?: number;
baz: boolean | undefined;
}
printTypeProperties<SomeType>();
/*
Prints:
foo: String, isOptional: false, isUnion: false, type: {Native String (String)}
bar: bar, isOptional: true, isUnion: true, type: {Container bar (bar)}
baz: baz, isOptional: false, isUnion: true, type: {Container baz (baz)}
*/ I was hoping the that the type name for bar would be something like Sorry if I'm hijacking the thread it just seemed like the issues might be related. I can open a new issue if that would be better. |
@aj-bartocci Each container type has multiple types inside. You can access them via About naming... Class has name, interface has name, function has name, type alias has name but other types (such as types of properties, fields, parameters etc.) don't have names in TS. So names of those containers are not intended. |
Got it that makes sense. Using |
Consider the following code:
The first check works fine and returns
true
.In the second check, the type of
s
is clearly a union, but it returnsfalse
.The same thing happens if I try to extract the types — the first statement correctly returns the two types, while the second one sometimes returns an empty array and sometimes return undefined.
I'm using Vite with HMR (btw the hot reloading doesn't trigger when the transformed input changes, it may or may not be a problem on your side of things).
The text was updated successfully, but these errors were encountered: