When I associate an attribute to a component, does the component not care about the base data type of the attribute ?

for eg: If I use an ui:outputtext component, I would assume lightning would error when I associate an Integer attribute type to value of an ui:outputtext . The below component compiles fine which to does not make sense.

Is this a feature or a bug?

When it comes to visualforce we have



Since lightning has separate ouputnumber and ouputtext tags, I assumed it would error when I try to associate number to a text and text to a number.


<aura:component controller="integer_controller">
    <aura:attribute name="int_val" type="Integer"/>
    <aura:attribute name="string_val" type="String"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    Output number : <ui:outputNumber aura:id="outNum" value="{!v.string_val}"/>
    output text: <ui:outputtext aura:id="outtext" value="{!v.int_val}"/>



    doInit: function(component, event, helper) {
        var servaction = component.get("c.intvalfromserver");
        var servaction2 = component.get("c.stringvalfromserver");
        servaction.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
        servaction2.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {

Server side controller:

public class integer_controller {
    public static Integer intvalfromserver() {
        return 10;
    public static String stringvalfromserver() {
        return 'abc';


Output number : abc

output text: 10

1 Answer 1


This was an intentional design decision by the component authors to not error.

You can see in the ui:outputText source code there's an explicit conditional block to create a text node when the input is a number instead of a string:


Similarly, in ui:outputNumber the input is treated the same if it's a string or a number:


  • Thanks for the reference, I could have never found that reference. So they do have validations to check if it is a number or string in the controller.
    – Rao
    Nov 15, 2016 at 22:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .