Skip to content
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

Don't unwrap functions #2061

Merged
merged 1 commit into from
Oct 15, 2018
Merged

Don't unwrap functions #2061

merged 1 commit into from
Oct 15, 2018

Conversation

hausdorff
Copy link
Contributor

Suppose I have pulumi.output(o).apply(foo), with o being type O
and foo taking type O as an argument. If O is a type with methods,
this will fail to type check.

The reason is that UnwrappedObject<T> (as well as the other
Unwrapped* types) will recursively box the field values whose type is
Function. Since UnwrappedObject<Function> is not the same as
Function, we fail to type check.

This commit resolves this by considering Function a primitive type,
which will cause us to not box these field values, instead leaving them
as Function.

var sentinel = function(_: () => void) {}

// `v` should be type `() => void` rather than `UnwrappedObject<void>`.
var _ = output(function() {}).apply(v => sentinel(v));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't really need the _ but i also don't care :)

@CyrusNajmabadi
Copy link
Contributor

This commit resolves this by considering Function a primitive type,
which will cause us to not box these field values, instead leaving them
as Function.

Also, to be clear. This is how the impl already works. It does not touch 'Function' instances. So this is just making sure that the TS typings reflect that fact.

Suppose you have `pulumi.output(o).apply(foo)`, with `o` being type `O`
and `foo` taking type `O` as an argument. If `O` is a type with methods,
this will fail to type check.

The reason is that `UnwrappedObject<T>` (as well as the other
`Unwrapped*` types) will recursively wrap the types of field values
whose type was `Function`. Since `UnwrappedObject<Function>` is not the
same as `Function`, we fail to type check. Note that this does not
result in an actual "boxed" object -- this is purely at the type level.

This commit resolves this by considering `Function` a primitive type,
which will cause us to not wrap the types of field values, instead
leaving them as `Function`.
@hausdorff hausdorff merged commit 00a22b2 into master Oct 15, 2018
@pulumi-bot pulumi-bot deleted the hausdorff/unwrap-fn branch October 15, 2018 21:28
@CyrusNajmabadi
Copy link
Contributor

@ellismg Encountered this as well in pulumi-service. So we're going to cherry pick this into our next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants