anyone know what’s up with intellisense in SST pro...
# help
s
anyone know what’s up with intellisense in SST projects?
environment
doesn’t show up as a property, but it should be. this might be a VS Code bug, seems like
f
Hmm.. I’ve seen a similar weird issue with IntelliSense https://github.com/serverless-stack/serverless-stack/issues/426
s
weird. mind if I add my case to that issue, since it could be related?
f
For sure!
I wasn’t able to figure it out when I last looked… probably I don’t know enough about it
If u have any hint.. lemme know… I will take another crack at it
t
I left a comment explaining it
The solution involves switching to a pattern called algebraic data types which are really really powerful but the apis might feel a bit more verbose
f
Ah I see… do you have an example of the syntax? just to get a taste of how verbose it is 😅
t
Basically the gist is to be able to identify the specific type inside a union type, you need a way to "discriminate" between them. So all the types need a common field that can serve as the discriminator
Copy code
type Rectangle = {
  kind: "square";
  width: number;
  height: number;
};

type Circle = {
  kind: "circle";
  radius: number;
};

type Shape = Rectangle | Circle

function test(s: Shape) {
  console.log(s.height) // type error
  if (s.kind === "square") {
    s.height // valid
  }
}
tsc is pretty smart about identifying these discriminators and using them to hint things to you
It lets you write really bullet proof code but you need to add discriminators everywhere
^ it omits
radius
because it knows that's not what you want
f
Oh nice.. I kinda like that 😂
t
I like it too, we can use it with
bundle
as well and have very nice developer experience where it shows them what options are available for a python bundle vs a go bundle
f
A problem with CDK so far is that the
instanceof
check is not reliable. ie. SST has the
@aws-cdk/aws-s3
dependency, and users can also have
@aws-cdk/aws-s3
as their dependency. If they are of different versions, the package is going to appear twice in side
node_modules
.
t
can peer dependencies help there?
use their version if available
f
Yeah we looked into that briefly.. forgot what the problem was. Yeah should look into it again.