https://pulumi.com logo
#typescript
Title
# typescript
i

icy-london-58403

02/17/2020, 6:59 PM
I'm trying to learn dynamic providers and I'm starting by wrapping a tool called netbox which does IPAM. I get this error:
Copy code
prefix.ts(130,21): error TS2564: Property 'endpoint' has no initializer and is not definitely assigned in the constructor.
prefix.ts(131,21): error TS2564: Property 'token' has no initializer and is not definitely assigned in the constructor.
prefix.ts(132,21): error TS2564: Property 'description' has no initializer and is not definitely assigned in the constructor.
I followed the directions on: https://www.pulumi.com/docs/intro/concepts/programming-model/#dynamicproviders I made my create return the same names as the
public readonly
members of my
Resource
. What am I doing wrong? Partial of my code:
Copy code
class PrefixProvider implements pulumi.dynamic.ResourceProvider {
    public async create(inputs: PrefixInputs): Promise<pulumi.dynamic.CreateResult> {
        pulumi.log.debug("prefix create...")
        let netboxClient = new Client({
            host: inputs.endpoint,
            token: inputs.token,
        })

        
        let description = `${inputs.platform} | ${inputs.region} | ${inputs.type} | ${inputs.name}`

        var async_function = async function(): Promise<AxiosResponse<createPrefixResponse>> {
            return await netboxClient.createPrefix({
                prefix: inputs.prefix,
                description: description,
                vrf: inputs.vrfID,
            })
        }

        const response = await async_function()

        return {
            id:  response.data.id.toString(),
            outs: {
                endpoint: inputs.endpoint,
                token: inputs.token,
                description: description,
            },
        }
    }

    public async delete(id: pulumi.ID, props: PrefixInputs): Promise<void> {
        pulumi.log.debug("prefix delete...")

        let netboxClient = new Client({
            host: props.endpoint,
            token: props.token,
        })

        var async_function = async function() {
            return await netboxClient.deletePrefix({
                id: Number(id),
            })
        }

        const response = await async_function()
    }
}

export class Prefix extends pulumi.dynamic.Resource {
    public readonly endpoint: pulumi.Output<string>
    public readonly token: pulumi.Output<string>
    public readonly description: pulumi.Output<string>

    constructor(name: string, props: PrefixResourceInputs, opts?: pulumi.CustomResourceOptions) {
        super(new PrefixProvider(), name, {...props, endpoint: undefined, token: undefined, description: undefined}, opts)
    }
}
m

microscopic-pilot-97530

02/19/2020, 8:48 PM
Hi @icy-london-58403, there are a couple ways to address this. One way is to add definite assignment assertions to each property. https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#definite-assignment-assertions Adding an exclamation point after the property names like:
Copy code
public readonly endpoint!: pulumi.Output<string>
    public readonly token!: pulumi.Output<string>
    public readonly description!: pulumi.Output<string>
Another way would be to set
strictPropertyInitialization
to
false
in
tsconfig.json
.
We need to update our example in the documentation. It was written before more recent versions of TypeScript got stricter about this by default.
i

icy-london-58403

02/19/2020, 9:11 PM
thanks let me give some of this a try
this worked. Thank you @microscopic-pilot-97530
🎉 1
8 Views