Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I've got an interface defined as such:

import {AppBuild} from '../models/app-build.model'

export interface Build {
    "Name": string
    "Builds"?: Array<AppBuild>
}

In my component, I've imported it:

import {Build} from '../../models/build.model'

But when I try to declare a variable as a Build:

build:Build;
build.Name = "Hi";

I get Cannot find name 'Build'.

Why would this be happening?

Here's that entire function if that helps:

let build:Build = new Build();
build.Name = "Hi";
console.log(buildNumber)
let tempBuildArray = new Array<Build>();

return build;
share|improve this question

You probably missed 'let' or 'var' keyword, and want to write variable declaration like this:

let build: Build;
//...Initialize your build variable with value here
build.Name = "Hi";

[EDIT]

If you insist on having 'Build' as interface you can initialize it like this:

let build: Build;
build = {Name: '123'};
build.Name = "Hi";

Or you can turn it into class:

export class Build 
{
    public Name: string;
    public Builds: Array<AppBuild>;

    constructor(name: string)
    {
         this.Name = name;
    }
}

and later:

let build: Build;
build = new Build('123');
build.Name = "Hi";

Hope this helps.

share|improve this answer
    
It doesn't seem to have worked. Adding the let made that part no longer be highlighted, but now I get cannot set property 'Name' of undefined. I tried setting build:Build = new Build() but it's telling me it doesn't know what Build() is. I'm at a loss. – Alex Kibler Mar 15 at 15:56
    
Check my update – Amid Mar 15 at 16:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.